Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test of laguage name. #1026

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ use super::*;
let contents = fs::read_to_string("{1}").unwrap();

println!("{{}} {1}", name);
assert_eq!(get_language!(contents), name);
println!("{{}} LANGUAGE MATCHES", name);
assert_eq!(get_digit!(LINES, contents), language.lines());
println!("{{}} LINES MATCH", name);
assert_eq!(get_digit!(CODE, contents), language.code);
Expand Down
10 changes: 9 additions & 1 deletion tests/accuracy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ use std::fs;

use once_cell::sync::Lazy;
use regex::Regex;
use tokei::{Config, Languages};
use tokei::{Config, Languages, LanguageType};

static LINES: Lazy<Regex> = Lazy::new(|| Regex::new(r"\d+ lines").unwrap());
static CODE: Lazy<Regex> = Lazy::new(|| Regex::new(r"\d+ code").unwrap());
static COMMENTS: Lazy<Regex> = Lazy::new(|| Regex::new(r"\d+ comments").unwrap());
static BLANKS: Lazy<Regex> = Lazy::new(|| Regex::new(r"\d+ blanks").unwrap());
static LANGUAGE: Lazy<Regex> = Lazy::new(|| Regex::new(r#"language: "([^"]+)"#).unwrap());

macro_rules! get_digit {
($regex:expr, $text:expr) => {{
Expand All @@ -26,6 +27,13 @@ macro_rules! get_digit {
}};
}

macro_rules! get_language {
($text:expr) => {{
let matched = LANGUAGE.captures(&$text).expect("Couldn't find language");
matched.get(1).unwrap().as_str().parse::<LanguageType>().unwrap()
}};
}

mod config {
use tokei::*;

Expand Down
2 changes: 1 addition & 1 deletion tests/data/Daml.daml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- ! 42 lines 24 code 9 comments 9 blanks
-- ! language: "daml" 42 lines 24 code 9 comments 9 blanks

{-
This code is derived from https://github.com/digital-asset/ex-secure-daml-infra/blob/master/daml/BobTrigger.daml
Expand Down
2 changes: 1 addition & 1 deletion tests/data/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 17 lines 7 code 3 comments 7 blanks
# language: "dockerfile" 17 lines 7 code 3 comments 7 blanks

FROM netbsd:7.0.2

Expand Down
2 changes: 1 addition & 1 deletion tests/data/MSBuild.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- 12 lines 10 code 1 comments 1 blanks -->
<!-- language: "msbuild" 12 lines 10 code 1 comments 1 blanks -->
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
Expand Down
2 changes: 1 addition & 1 deletion tests/data/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 24 lines 11 code 5 comments 8 blanks
# language: "makefile" 24 lines 11 code 5 comments 8 blanks

## ##
## IMPORTANT COMMENT ##
Expand Down
2 changes: 1 addition & 1 deletion tests/data/NuGet.Config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- 24 lines 13 code 8 comments 3 blanks -->
<!-- language: "nuget config" 24 lines 13 code 8 comments 3 blanks -->

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
Expand Down
2 changes: 1 addition & 1 deletion tests/data/Rakefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 10 lines 4 code 2 comments 4 blanks
# language: "rakefile" 10 lines 4 code 2 comments 4 blanks

# this is a rakefile

Expand Down
2 changes: 1 addition & 1 deletion tests/data/SConstruct
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!python
# 10 lines 3 code 3 comments 4 blanks
# language: "scons" 10 lines 3 code 3 comments 4 blanks

# this is a comment

Expand Down
2 changes: 1 addition & 1 deletion tests/data/Tera.tera
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{# 42 lines 26 code 11 comments 5 blanks #}
{# language: "tera" 42 lines 26 code 11 comments 5 blanks #}
<!DOCTYPE html>
<html>
<head>
Expand Down
2 changes: 1 addition & 1 deletion tests/data/abnf.abnf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; 11 lines 3 code 5 comments 3 blanks
; language: "abnf" 11 lines 3 code 5 comments 3 blanks
; comment line 0
; comment line 1

Expand Down
2 changes: 1 addition & 1 deletion tests/data/alloy.als
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 18 lines 10 code 3 comments 5 blanks
// language: "alloy" 18 lines 10 code 3 comments 5 blanks

sig Node {
edge: set Node
Expand Down
2 changes: 1 addition & 1 deletion tests/data/arduino.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 23 lines 13 code 6 comments 4 blanks
// language: "arduino c++" 23 lines 13 code 6 comments 4 blanks

int led = 13;

Expand Down
2 changes: 1 addition & 1 deletion tests/data/asciidoc.adoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 20 lines 5 code 8 comments 7 blanks
// language: "asciidoc" 20 lines 5 code 8 comments 7 blanks

= AsciiDoc title

Expand Down
2 changes: 1 addition & 1 deletion tests/data/asn1.asn1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- 34 lines 16 code 11 comments 7 blanks
-- language: "asn.1" 34 lines 16 code 11 comments 7 blanks
PKCS-12 {
iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) pkcs-12(12)
modules(0) pkcs-12(1) }
Expand Down
2 changes: 1 addition & 1 deletion tests/data/ats.dats
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! 42 lines 25 code 9 comments 8 blanks
//! language: "ats" 42 lines 25 code 9 comments 8 blanks

(*************
Reference:
Expand Down
2 changes: 1 addition & 1 deletion tests/data/awk.awk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/awk -f
# 5 lines 1 code 3 comments 1 blanks
# language: "awk" 5 lines 1 code 3 comments 1 blanks

# This is a comment
{ print $0 }
4 changes: 2 additions & 2 deletions tests/data/bazel.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 18 lines 13 code 3 comments 2 blanks
# language: "bazel" 18 lines 13 code 3 comments 2 blanks

# build hello-greet
cc_library(
Expand All @@ -15,4 +15,4 @@ cc_binary(
":hello-greet",
"//lib:hello-time",
],
)
)
2 changes: 1 addition & 1 deletion tests/data/bean.bean
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; 27 lines 13 code 6 comments 8 blanks
; language: "bean" 27 lines 13 code 6 comments 8 blanks

option "operating_currency" "EUR"

Expand Down
2 changes: 1 addition & 1 deletion tests/data/bitbake.bb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 23 lines 13 code 5 comments 5 blanks
# language: "bitbake" 23 lines 13 code 5 comments 5 blanks
#
# This file was derived from the 'Hello World!' example recipe in the
# Yocto Project Development Manual.
Expand Down
4 changes: 2 additions & 2 deletions tests/data/brightscript.brs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
' 26 lines 10 code 13 comments 3 blanks
' language: "brightscript" 26 lines 10 code 13 comments 3 blanks
' /**
' * @member difference
' * @memberof module:rodash
Expand All @@ -23,4 +23,4 @@ Function rodash_difference_(first, second)
end for

return result
End Function
End Function
2 changes: 1 addition & 1 deletion tests/data/c.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 50 lines 33 code 8 comments 9 blanks
// language: "c" 50 lines 33 code 8 comments 9 blanks

/* /* we can't nest block comments in c, but we can start one */
int main(void) {
Expand Down
2 changes: 1 addition & 1 deletion tests/data/clojure.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; 19 lines 13 code 3 comments 3 blanks
; language: "clojure" 19 lines 13 code 3 comments 3 blanks

(ns clojure)

Expand Down
2 changes: 1 addition & 1 deletion tests/data/clojurec.cljc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; 19 lines 13 code 3 comments 3 blanks
; language: "clojurec" 19 lines 13 code 3 comments 3 blanks

(ns clojure)

Expand Down
2 changes: 1 addition & 1 deletion tests/data/clojurescript.cljs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; 19 lines 13 code 3 comments 3 blanks
; language: "clojurescript" 19 lines 13 code 3 comments 3 blanks

(ns clojure)

Expand Down
2 changes: 1 addition & 1 deletion tests/data/cmake.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 25 lines 16 code 3 comments 6 blanks
# language: "cmake" 25 lines 16 code 3 comments 6 blanks

SET(_POSSIBLE_XYZ_INCLUDE include include/xyz)
SET(_POSSIBLE_XYZ_EXECUTABLE xyz)
Expand Down
2 changes: 1 addition & 1 deletion tests/data/codeql.ql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! 40 lines 17 code 15 comments 8 blanks
//! language: "codeql" 40 lines 17 code 15 comments 8 blanks

/**
* @name fu
Expand Down
2 changes: 1 addition & 1 deletion tests/data/cogent.cogent
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- 7 lines 2 code 2 comments 3 blanks
-- language: "cogent" 7 lines 2 code 2 comments 3 blanks

type A -- uncounted comment

Expand Down
2 changes: 1 addition & 1 deletion tests/data/cpp.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* 46 lines 37 code 3 comments 6 blanks */
/* language: "c++" 46 lines 37 code 3 comments 6 blanks */

#include <stdio.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/data/crystal.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 20 lines 14 code 2 comments 4 blanks
# language: "crystal" 20 lines 14 code 2 comments 4 blanks
x = 3
if x < 2
p = "Smaller"
Expand Down
2 changes: 1 addition & 1 deletion tests/data/csharp.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 26 lines 14 code 9 comments 3 blanks
// language: "c#" 26 lines 14 code 9 comments 3 blanks
namespace Ns
{
/*
Expand Down
2 changes: 1 addition & 1 deletion tests/data/cuda.cu
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* 7 lines 4 code 2 comments 1 blanks */
/* language: "cuda" 7 lines 4 code 2 comments 1 blanks */

// add vector
__host__ void add(const int* a, const int* b, int* c) {
Expand Down
2 changes: 1 addition & 1 deletion tests/data/cython.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 29 lines, 21 code, 3 comments, 5 blanks
# language: "cython" 29 lines, 21 code, 3 comments, 5 blanks


def add(x, y):
Expand Down
2 changes: 1 addition & 1 deletion tests/data/d.d
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* 8 lines 5 code 1 comments 2 blanks */
/* language: "d" 8 lines 5 code 1 comments 2 blanks */

void main() {
auto x = 5; /+ a /+ nested +/ comment /* +/
Expand Down
2 changes: 1 addition & 1 deletion tests/data/dhall.dhall
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- 16 lines 9 code 5 comments 2 blanks
-- language: "dhall" 16 lines 9 code 5 comments 2 blanks
{- A comment within the interior of a multi-line literal counts as part of the
literal
-}
Expand Down
2 changes: 1 addition & 1 deletion tests/data/dreammaker.dm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 17 lines 7 code 6 comments 4 blanks
// language: "dream maker" 17 lines 7 code 6 comments 4 blanks
/*
* /* Hello! */
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/data/dust.dust
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{! 10 lines 2 code 5 comments 3 blanks !}
{! language: "dust.js" 10 lines 2 code 5 comments 3 blanks !}

{! All Dust comments are multiline comments. And there's no quoting
comment openers and closers. Instead there are escape sequences
Expand Down
2 changes: 1 addition & 1 deletion tests/data/ebuild.ebuild
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 16 lines 9 code 2 comments 5 blanks
# language: "ebuild" 16 lines 9 code 2 comments 5 blanks

# test comment

Expand Down
2 changes: 1 addition & 1 deletion tests/data/edgeql.edgeql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 28 lines 21 code 3 comments 4 blanks
# language: "edgeql" 28 lines 21 code 3 comments 4 blanks

select User {
name,
Expand Down
2 changes: 1 addition & 1 deletion tests/data/edn.edn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; 11 lines 6 code 2 comments 3 blanks
; language: "edn" 11 lines 6 code 2 comments 3 blanks

; Just some random data

Expand Down
2 changes: 1 addition & 1 deletion tests/data/elvish.elv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 16 lines, 9 code, 5 blanks, 2 comments
# language: "elvish" 16 lines, 9 code, 5 blanks, 2 comments
echo "This is a
multiline string
# with a hash
Expand Down
2 changes: 1 addition & 1 deletion tests/data/emacs_dev_env.ede
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;; 16 lines 6 code 7 comments 3 blanks
;; language: "emacs dev env" 16 lines 6 code 7 comments 3 blanks

;; This is an EDE Project file

Expand Down
2 changes: 1 addition & 1 deletion tests/data/emacs_lisp.el
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;; 21 lines 11 code 6 comments 4 blanks
;; language: "Emacs Lisp" 21 lines 11 code 6 comments 4 blanks

; This is a comment line
;; This too!
Expand Down
2 changes: 1 addition & 1 deletion tests/data/emojicode.🍇
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
💭 24 lines 10 code 10 comments 4 blanks
💭 language: "emojicode" 24 lines 10 code 10 comments 4 blanks

📘
This package is neat.
Expand Down
2 changes: 1 addition & 1 deletion tests/data/esdl.esdl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 20 lines 13 code 4 comments 3 blanks
# language: "edgedb schema definition" 20 lines 13 code 4 comments 3 blanks

# no module block
type default::Movie {
Expand Down
2 changes: 1 addition & 1 deletion tests/data/example.umpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
! 68 lines 58 code 2 comments 8 blanks
! language: "umpl" 68 lines 58 code 2 comments 8 blanks

create yum with 5
create num with ((plus 7 6 6 yum))>
Expand Down
2 changes: 1 addition & 1 deletion tests/data/factor.factor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
! 14 lines, 5 code, 6 comments, 3 blanks
! language: "factor" 14 lines, 5 code, 6 comments, 3 blanks

/* we can use some dependencies */
USING: math multiline sequences ;
Expand Down
2 changes: 1 addition & 1 deletion tests/data/fennel.fnl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;; 18 lines 8 code 5 comments 5 blanks
;; language: "fennel" 18 lines 8 code 5 comments 5 blanks

; this is a ; single comment
;;;; this is also a single comment ;;;;;;
Expand Down
2 changes: 1 addition & 1 deletion tests/data/flatbuffers.fbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 34 lines 21 code 6 comments 7 blanks
// language: "FlatBuffers Schema" 34 lines 21 code 6 comments 7 blanks

include "another_schema.fbs";

Expand Down
2 changes: 1 addition & 1 deletion tests/data/forgecfg.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 79 lines 20 code 40 comments 19 blanks
# language: "Forge Config" 79 lines 20 code 40 comments 19 blanks

# Configuration file

Expand Down
2 changes: 1 addition & 1 deletion tests/data/fsharp.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(* 15 lines 6 code 5 comments 4 blanks *)
(* language: "f#" 15 lines 6 code 5 comments 4 blanks *)

// Comment

Expand Down
2 changes: 1 addition & 1 deletion tests/data/fstar.fst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(* 11 lines 3 code 5 comments 3 blanks *)
(* language: "f*" 11 lines 3 code 5 comments 3 blanks *)

module Hello

Expand Down
2 changes: 1 addition & 1 deletion tests/data/ftl.ftl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<#-- 10 lines 5 code 3 comments 2 blanks -->
<#-- language: "freemarker" 10 lines 5 code 3 comments 2 blanks -->
<#ftl output_format="plainText"/>

<#-- Define the print macro -->
Expand Down
2 changes: 1 addition & 1 deletion tests/data/futhark.fut
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- 8 lines 2 code 3 comments 3 blanks
-- language: "futhark" 8 lines 2 code 3 comments 3 blanks

-- this is a test file

Expand Down
2 changes: 1 addition & 1 deletion tests/data/gas.S
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 67 lines 46 code 10 comments 11 blanks
// language: "gnu style assembly" 67 lines 46 code 10 comments 11 blanks
#include "config.h"

/* BIG FAT WARNING GOES HERE */
Expand Down
2 changes: 1 addition & 1 deletion tests/data/gdb.gdb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 15 lines 7 code 5 comments 3 blanks
# language: "gdb script" 15 lines 7 code 5 comments 3 blanks
#
# This is a comment line. We don't have multi-comment lines
#
Expand Down
2 changes: 1 addition & 1 deletion tests/data/gherkin.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 13 lines 8 code 3 comments 2 blanks
# language: "gherkin (cucumber)" 13 lines 8 code 3 comments 2 blanks
Feature: Guess the word

# The first example has two steps
Expand Down
2 changes: 1 addition & 1 deletion tests/data/gleam.gleam
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//// 34 lines 24 code 4 comments 6 blanks
//// language: "gleam" 34 lines 24 code 4 comments 6 blanks

import gleam/option.{Option, None}
import gleam/io
Expand Down
Loading
Loading