1 require File.dirname(__FILE__) + '/../test_helper'
5 class DetectorTest < LingoTest
8 def do_detect(filename, filenames = [])
9 file_location = File.dirname(__FILE__) + "/../detect_files/" + filename
10 sfc = Ohcount::SimpleFileContext.new(filename, filenames, nil, file_location)
11 Ohcount::Detector.detect(sfc)
14 def test_matlab_or_objective_c
15 assert_equal 'objective_c', do_detect("t1.m")
16 assert_equal 'objective_c', do_detect("t2.m")
19 def test_detect_polyglot
20 assert_equal "cncpp", do_detect("foo.c")
21 assert_equal "ruby", do_detect("foo.rb")
22 assert_equal "matlab", do_detect("foo_matlab.m", ["foo_matlab.m", "bar.m", "README"])
23 assert_equal "objective_c", do_detect("foo_objective_c.m", ["foo_objective_c.m", "bar.h", "README"])
24 assert_equal "objective_c", do_detect("foo_objective_c.h", ["foo_objective_c.h, different_than_foo.m"])
25 assert_equal "php", do_detect("upper_case_php")
26 assert_equal "lisp", do_detect("core.lisp")
27 assert_equal "dmd", do_detect("foo.d")
30 def test_upper_case_extensions
31 assert_equal "cncpp", do_detect("foo_upper_case.C")
32 assert_equal "ruby", do_detect("foo_upper_case.RB")
35 def test_no_extensions
36 assert_equal "python", do_detect("py_script", [])
37 assert_equal "ruby", do_detect("ruby_script", [])
38 assert_equal "shell", do_detect("bourne_again_script", [])
39 assert_equal "shell", do_detect("findup", [])
40 assert_equal "perl", do_detect("renrot", [])
41 assert_equal "dmd", do_detect("d_script", [])
44 def test_csharp_or_clearsilver
45 assert_equal 'csharp', do_detect("cs1.cs")
46 assert_equal 'clearsilver_template', do_detect("clearsilver_template1.cs")