1 require File.dirname(__FILE__) + '/../test_helper'
4 # DetectorTest covers all Detector scenarios.
6 # The directory <tt>test/detect_files</tt> contains test files for the detector.
7 # These files are not used in parser testing; they are strictly for detection.
11 # To manually test an addition to the detector, rebuild ohcount and run it against
15 # bin/ohcount --detect test/detect_files/my_file.ext
17 # If the detector is working, you should see the name of your expected language:
19 # my_language test/detect_files/my_file.ext
21 class Ohcount::DetectorTest < Ohcount::Test
23 def do_detect(filename, filenames = [])
24 file_location = File.dirname(__FILE__) + "/../detect_files/" + filename
25 sfc = Ohcount::SimpleFileContext.new(filename, filenames, nil, file_location)
26 Ohcount::Detector.detect(sfc)
29 def test_matlab_or_objective_c
30 assert_equal 'objective_c', do_detect("t1.m")
31 assert_equal 'objective_c', do_detect("t2.m")
34 def text_fortran_fixedfree
35 assert_equal 'fortranfixed', do_detect("fortranfixed.f")
36 assert_equal 'fortranfree', do_detect("fortranfree.f")
39 def test_detect_polyglot
40 assert_equal "c", do_detect("foo.c")
41 assert_equal "c", do_detect("uses_no_cpp.h")
42 assert_equal "cpp", do_detect("uses_cpp_headers.h")
43 assert_equal "cpp", do_detect("uses_cpp_stdlib_headers.h")
44 assert_equal "cpp", do_detect("uses_cpp_keywords.h")
45 assert_equal "ruby", do_detect("foo.rb")
46 assert_equal "matlab", do_detect("foo_matlab.m", ["foo_matlab.m", "bar.m", "README"])
47 assert_equal "objective_c", do_detect("foo_objective_c.m", ["foo_objective_c.m", "bar.h", "README"])
48 assert_equal "objective_c", do_detect("foo_objective_c.h", ["foo_objective_c.h, different_than_foo.m"])
49 assert_equal "php", do_detect("upper_case_php")
50 assert_equal "smalltalk", do_detect("example.st")
51 assert_equal "vala", do_detect("foo.vala")
52 assert_equal "tex", do_detect("foo.tex")
53 assert_equal "xslt", do_detect("example.xsl")
54 assert_equal "lisp", do_detect("core.lisp")
55 assert_equal "dmd", do_detect("foo.d")
58 def test_upper_case_extensions
59 assert_equal "cpp", do_detect("foo_upper_case.C")
60 assert_equal "ruby", do_detect("foo_upper_case.RB")
63 def test_no_extensions
64 assert_equal "python", do_detect("py_script", [])
65 assert_equal "ruby", do_detect("ruby_script", [])
66 assert_equal "shell", do_detect("bourne_again_script", [])
67 assert_equal "shell", do_detect("bash_script", [])
68 assert_equal "perl", do_detect("perl_w", [])
69 assert_equal "dmd", do_detect("d_script", [])
72 def test_csharp_or_clearsilver
73 assert_equal 'csharp', do_detect("cs1.cs")
74 assert_equal 'clearsilver_template', do_detect("clearsilver_template1.cs")