@ -17,13 +17,70 @@ describe("compiler pass |reportLeftRecursion|", function() {
} ) ;
describe ( "in sequences" , function ( ) {
it ( "reports left recursion only for the first element" , function ( ) {
expect ( pass ) . toReportError ( 'start = start "a" "b"' , {
message : 'Left recursion detected for rule \"start\".'
} ) ;
it ( "reports left recursion if all preceding elements match empty string" , function ( ) {
expect ( pass ) . toReportError ( 'start = "" "" "" start' ) ;
} ) ;
it ( "doesn't report left recursion if some preceding element doesn't match empty string" , function ( ) {
expect ( pass ) . not . toReportError ( 'start = "a" "" "" start' ) ;
expect ( pass ) . not . toReportError ( 'start = "" "a" "" start' ) ;
expect ( pass ) . not . toReportError ( 'start = "" "" "a" start' ) ;
} ) ;
it ( "computes empty string matching correctly" , function ( ) {
expect ( pass ) . toReportError ( 'start = ("" / "a" / "b") start' ) ;
expect ( pass ) . toReportError ( 'start = ("a" / "" / "b") start' ) ;
expect ( pass ) . toReportError ( 'start = ("a" / "b" / "") start' ) ;
expect ( pass ) . not . toReportError ( 'start = ("a" / "b" / "c") start' ) ;
expect ( pass ) . toReportError ( 'start = ("" { }) start' ) ;
expect ( pass ) . not . toReportError ( 'start = ("a" { }) start' ) ;
expect ( pass ) . toReportError ( 'start = ("" "" "") start' ) ;
expect ( pass ) . not . toReportError ( 'start = ("a" "" "") start' ) ;
expect ( pass ) . not . toReportError ( 'start = ("" "a" "") start' ) ;
expect ( pass ) . not . toReportError ( 'start = ("" "" "a") start' ) ;
expect ( pass ) . toReportError ( 'start = a:"" start' ) ;
expect ( pass ) . not . toReportError ( 'start = a:"a" start' ) ;
expect ( pass ) . toReportError ( 'start = $"" start' ) ;
expect ( pass ) . not . toReportError ( 'start = $"a" start' ) ;
expect ( pass ) . toReportError ( 'start = &"" start' ) ;
expect ( pass ) . toReportError ( 'start = &"a" start' ) ;
expect ( pass ) . toReportError ( 'start = !"" start' ) ;
expect ( pass ) . toReportError ( 'start = !"a" start' ) ;
expect ( pass ) . toReportError ( 'start = ""? start' ) ;
expect ( pass ) . toReportError ( 'start = "a"? start' ) ;
expect ( pass ) . toReportError ( 'start = ""* start' ) ;
expect ( pass ) . toReportError ( 'start = "a"* start' ) ;
expect ( pass ) . toReportError ( 'start = ""+ start' ) ;
expect ( pass ) . not . toReportError ( 'start = "a"+ start' ) ;
expect ( pass ) . toReportError ( 'start = &{ } start' ) ;
expect ( pass ) . toReportError ( 'start = !{ } start' ) ;
expect ( pass ) . toReportError ( [
'start = a start' ,
'a = ""'
] . join ( '\n' ) ) ;
expect ( pass ) . not . toReportError ( [
'start = a start' ,
'a = "a"'
] . join ( '\n' ) ) ;
expect ( pass ) . toReportError ( 'start = "" start' ) ;
expect ( pass ) . not . toReportError ( 'start = "a" start' ) ;
expect ( pass ) . not . toReportError ( 'start = [a-d] start' ) ;
expect ( pass ) . not . toReportError ( 'start = "a" start "b"' ) ;
expect ( pass ) . not . toReportError ( 'start = "a" "b" start' ) ;
expect ( pass ) . not . toReportError ( 'start = "." start' ) ;
} ) ;
} ) ;
} ) ;