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 test_detect_polyglot
35 assert_equal "cncpp", do_detect("foo.c")
36 assert_equal "ruby", do_detect("foo.rb")
37 assert_equal "matlab", do_detect("foo_matlab.m", ["foo_matlab.m", "bar.m", "README"])
38 assert_equal "objective_c", do_detect("foo_objective_c.m", ["foo_objective_c.m", "bar.h", "README"])
39 assert_equal "objective_c", do_detect("foo_objective_c.h", ["foo_objective_c.h, different_than_foo.m"])
40 assert_equal "php", do_detect("upper_case_php")
41 assert_equal "vala", do_detect("foo.vala")
42 assert_equal "tex", do_detect("foo.tex")
43 assert_equal "xslt", do_detect("example.xsl")
44 assert_equal "lisp", do_detect("core.lisp")
45 assert_equal "dmd", do_detect("foo.d")
48 def test_upper_case_extensions
49 assert_equal "cncpp", do_detect("foo_upper_case.C")
50 assert_equal "ruby", do_detect("foo_upper_case.RB")
53 def test_no_extensions
54 assert_equal "python", do_detect("py_script", [])
55 assert_equal "ruby", do_detect("ruby_script", [])
56 assert_equal "shell", do_detect("bourne_again_script", [])
57 assert_equal "shell", do_detect("bash_script", [])
58 assert_equal "perl", do_detect("perl_w", [])
59 assert_equal "dmd", do_detect("d_script", [])
62 def test_csharp_or_clearsilver
63 assert_equal 'csharp', do_detect("cs1.cs")
64 assert_equal 'clearsilver_template', do_detect("clearsilver_template1.cs")