Skip to content

Commit

Permalink
Add vscode-tmgrammar-test module, include tests in ci, add unit and s…
Browse files Browse the repository at this point in the history
…napshot tests for lexical constructs
  • Loading branch information
PanAeon committed May 22, 2019
1 parent 7ff15a6 commit 4bde54b
Show file tree
Hide file tree
Showing 10 changed files with 4,190 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
tests/**
src/**
node_modules
.gitkeep
.gitkeep
scripts
1 change: 1 addition & 0 deletions bin/ci-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ NEW_VERSION=${TRAVIS_TAG#"v"}
# Build the extension
yarn install
yarn build
yarn test

# Update package.json and CHANGELOG.md
set-up-ssh() {
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@
"ts-node": "^8.1.0",
"tsc": "^1.20150623.0",
"typescript": "^3.3.3",
"vscode-tmgrammar-test": "0.0.4",
"vsce": "^1.59.0"
},
"scripts": {
"vscode:prepublish": "test -f ./syntaxes/Scala.tmLanguage.json",
"vscode:publish": "vsce publish --yarn",
"build": "ts-node src/typescript/GenerateTmLanguageFile.ts > ./syntaxes/Scala.tmLanguage.json"
"build": "ts-node src/typescript/GenerateTmLanguageFile.ts > ./syntaxes/Scala.tmLanguage.json",
"test": "node scripts/unit.js && node scripts/snap.js"
}
}
9 changes: 9 additions & 0 deletions scripts/snap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var cp = require('child_process')

try {
cp.execSync("npx vscode-tmgrammar-snap -s source.scala -g syntaxes/Scala.tmLanguage.json -t 'tests/snap/**/*.test.scala'",
{ stdio: 'inherit' })
} catch(err) {
console.debug(err.toString())
process.exit(-1)
}
9 changes: 9 additions & 0 deletions scripts/unit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var cp = require('child_process')

try {
cp.execSync("npx vscode-tmgrammar-test -s source.scala -g syntaxes/Scala.tmLanguage.json -t 'tests/unit/**/*.test.scala'",
{ stdio: 'inherit' })
} catch(err) {
console.debug(err.toString())
process.exit(-1)
}
23 changes: 23 additions & 0 deletions tests/sample.test.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SYNTAX TEST "source.scala"

// line which start with a <comment token> but don't have valid assertions are ignored

class Stack[A] {
// <----- keyword.declaration.scala
// ^ - keyword.declaration.scala entity.name.class.declaration
// ^^^^^ entity.name.class.declaration
// ^ source.scala meta.bracket.scala
// ^ entity.name.class
// ^ meta.bracket.scala
// ^ punctuation.section.block.begin.scala
private var elements: List[A] = Nil
def push(x: A) { elements = x :: elements }
def peek: A = elements.head
def pop(): A = {
val currentTop = peek
elements = elements.tail
currentTop
}
// <~~- punctuation.section.block.end.scala
}

78 changes: 78 additions & 0 deletions tests/snap/lexical.test.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@

object ExampleIdentifiers {
val x = 3
val Object = 3
val maxIndex = 3
val p2p = 3
val empty_? = 3
val + = 3
val `yield` = 3
val αρετη = 3
val _y = 3
val dot_product_* = 3
val __system = 3
val _MAX_LEN_ = 3
}

object IntegerLiterals {
(0, 21, 0xFFFFFFFF, -42L)
}

object FloatingPointLiterals {
( 0.0, 1e30f, 3.14159f, 1.0e-100, .1 )
}

object Boolean {
(true, false)
}

object CharacterLiterals {
('a', '\u0041', '\n', '\t')
}

object StringLiterals {
("Hello,\nWorld!", "This string contains a \" character.")

"""the present string
spans three
lines."""

"""the present string
|spans three
|lines.""".stripMargin


val escapeSequences = "\b\t\n\f\r\"\'\\"

s"$x plain ${val x = y}"
custom"$x plain ${val x = y}"

s"""$x plain ${val x = y}"""
custom"""$x plain ${val x = y}"""
}

object Symbols {
('x, 'X, 'αρετη, '=, '+ )
}

// single line comment

/*
multiline comment*/

/**
* Scaladoc comment
* @scaladoc @param
*/

/* nested /* multi-line */ comment */


object Xml {
val b = <book>
<title>The Scala Language Specification</title>
<version>{scalaBook.version}</version>
<authors>{scalaBook.authors.mkList("", ", ", "")}</authors>
</book>
}
Loading

0 comments on commit 4bde54b

Please sign in to comment.