Skip to content

Commit

Permalink
Added basic unit tests for Prolog parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmoura committed Aug 7, 2011
1 parent f9ae4ee commit de940f2
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/parsers/prolog.rl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,14 @@ enum {
}

prolog_line_comment = '%' @comment nonnewline*;
prolog_block_comment = '/*' any* :>> '*/';
prolog_block_comment =
'/*' @comment (
newline %{ entity = INTERNAL_NL; } %prolog_ccallback
|
ws
|
(nonnewline - ws) @comment
)* :>> '*/';
prolog_comment = prolog_line_comment | prolog_block_comment;

prolog_sq_str = '\'' @code ([^\r\n\f'\\] | '\\' nonnewline)* '\'';
Expand Down
2 changes: 2 additions & 0 deletions test/detect_files/foo_perl1.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/perl
print "Hello, world!\n";
3 changes: 3 additions & 0 deletions test/detect_files/foo_perl2.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

# Also a Perl file but without the shebang line
print "Hello, world!\n";
6 changes: 6 additions & 0 deletions test/detect_files/foo_prolog1.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

% select(Element, List, Remaining)

select(H, [H| T], T).
select(H, [X| R], [X| T]) :-
select(H, R, T).
9 changes: 9 additions & 0 deletions test/expected_dir/prolog.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
prolog comment /* test file for Prolog parsing */
prolog blank
prolog comment % this is a Prolog source file
prolog blank
prolog comment % select(Element, List, Remaining)
prolog blank
prolog code select(H, [H| T], T).
prolog code select(H, [X| R], [X| T]) :-
prolog code select(H, R, T).
9 changes: 9 additions & 0 deletions test/src_dir/prolog.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* test file for Prolog parsing */

% this is a Prolog source file

% select(Element, List, Remaining)

select(H, [H| T], T).
select(H, [X| R], [X| T]) :-
select(H, R, T).
8 changes: 8 additions & 0 deletions test/unit/detector_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ void test_detector_disambiguate_m() {
void test_detector_disambiguate_in() {
ASSERT_NODETECT("empty.in");
}

void test_detector_disambiguate_pl() {
ASSERT_DETECT(LANG_PERL, "foo_perl1.pl");
ASSERT_DETECT(LANG_PERL, "foo_perl2.pl");
ASSERT_DETECT(LANG_PROLOG, "foo_prolog1.pl");
}

void test_detector_disambiguate_pro() {
ASSERT_DETECT(LANG_IDL_PVWAVE, "foo.pro");
ASSERT_DETECT(LANG_MAKE, "qmake.pro");
Expand Down Expand Up @@ -169,6 +176,7 @@ void all_detector_tests() {
test_detector_smalltalk();
test_detector_disambiguate_m();
test_detector_disambiguate_in();
test_detector_disambiguate_pl();
test_detector_disambiguate_pro();
test_detector_fortran_fixedfree();
test_detector_detect_polyglot();
Expand Down

0 comments on commit de940f2

Please sign in to comment.