Skip to content

Commit

Permalink
OTWO-3077 Expand Grace lang test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
notalex committed Jun 21, 2017
1 parent 991ba21 commit 56cfdf6
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 4 deletions.
7 changes: 7 additions & 0 deletions test/detect_files/grace1.grace
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Sample Grace code

import "parsers-test" as parsers

class exports {
def program = rule {codeSequence ~ rep(ws) ~ end}
}
2 changes: 2 additions & 0 deletions test/detect_files/grace2.grc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Sample Grace code
print "OK"
48 changes: 46 additions & 2 deletions test/expected_dir/grace.grace
Original file line number Diff line number Diff line change
@@ -1,2 +1,46 @@
grace lcomment // Sample Grace code
grace lcode print "OK"
grace comment //////////////////////////////////////////////////
grace comment // Sample Grace code
grace blank
grace code import "parsers-test" as parsers
grace blank
grace code class exports {
grace code inherit parsers.exports
grace comment //BEGINGRAMMAR
grace comment // top level
grace code def program = rule {codeSequence ~ rep(ws) ~ end}
grace code def codeSequence = rule { repdel((declaration | statement | empty), semicolon) }
grace code def hashLine = rule { (symbol "#") ~ rep(anyChar | space) ~ (newLine | end) }
grace blank
grace comment // def comment =
grace blank
grace comment //def oldClassDeclaration = rule { classId ~ identifier ~ lBrace ~
grace comment // opt(genericFormals ~ blockFormals ~ arrow) ~ codeSequence ~ rBrace }
grace blank
grace code def typeOpExpression = rule { rep1sep(basicTypeExpression, typeOp) }
grace blank
grace code def typeOpExpression = rule {
grace code var otherOperator
grace code basicTypeExpression ~ opt(ws) ~
grace code opt( guard(typeOp, { s -> otherOperator:= s;
grace code true }) ~ rep1sep(basicTypeExpression ~ opt(ws),
grace code guard(typeOp, { s -> s == otherOperator })
grace code )
grace code )
grace code }
grace blank
grace comment // "literals"
grace code def literal = rule { stringLiteral | selfLiteral | blockLiteral | numberLiteral | objectLiteral | lineupLiteral | typeLiteral }
grace blank
grace comment // terminals
grace code def backslash = token "\\" // doesn't belong here, doesn't work if left below!
grace blank
grace code def colon = rule {both(symbol ":", not(assign))}
grace code def newLine = symbol "\n"
grace code def lParen = symbol "("
grace code def rParen = symbol ")"
grace blank
grace code def reservedOp = rule {assign | equals | dot | arrow | colon | semicolon} // this is not quite right
grace blank
grace comment //ENDGRAMMAR
grace code }
grace blank
46 changes: 45 additions & 1 deletion test/src_dir/grace.grace
Original file line number Diff line number Diff line change
@@ -1,2 +1,46 @@
//////////////////////////////////////////////////
// Sample Grace code
print "OK"

import "parsers-test" as parsers

class exports {
inherit parsers.exports
//BEGINGRAMMAR
// top level
def program = rule {codeSequence ~ rep(ws) ~ end}
def codeSequence = rule { repdel((declaration | statement | empty), semicolon) }
def hashLine = rule { (symbol "#") ~ rep(anyChar | space) ~ (newLine | end) }

// def comment =

//def oldClassDeclaration = rule { classId ~ identifier ~ lBrace ~
// opt(genericFormals ~ blockFormals ~ arrow) ~ codeSequence ~ rBrace }

def typeOpExpression = rule { rep1sep(basicTypeExpression, typeOp) }

def typeOpExpression = rule {
var otherOperator
basicTypeExpression ~ opt(ws) ~
opt( guard(typeOp, { s -> otherOperator:= s;
true }) ~ rep1sep(basicTypeExpression ~ opt(ws),
guard(typeOp, { s -> s == otherOperator })
)
)
}

// "literals"
def literal = rule { stringLiteral | selfLiteral | blockLiteral | numberLiteral | objectLiteral | lineupLiteral | typeLiteral }

// terminals
def backslash = token "\\" // doesn't belong here, doesn't work if left below!

def colon = rule {both(symbol ":", not(assign))}
def newLine = symbol "\n"
def lParen = symbol "("
def rParen = symbol ")"

def reservedOp = rule {assign | equals | dot | arrow | colon | semicolon} // this is not quite right

//ENDGRAMMAR
}

3 changes: 2 additions & 1 deletion test/unit/detector_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ void test_detector_detect_polyglot() {
ASSERT_DETECT(LANG_FORTH, "forth.4th");
ASSERT_DETECT(LANG_FORTH, "forth.fr");
ASSERT_DETECT(LANG_FSHARP, "fs1.fs");
ASSERT_DETECT(LANG_GRACE, "grace.grace");
ASSERT_DETECT(LANG_GRACE, "grace1.grace");
ASSERT_DETECT(LANG_GRACE, "grace2.grc");
ASSERT_DETECT(LANG_AUTOCONF, "m4.m4");
ASSERT_DETECT(LANG_NSIS, "foo.nsi");
ASSERT_DETECT(LANG_NSIS, "foo.nsh");
Expand Down

0 comments on commit 56cfdf6

Please sign in to comment.