-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b3a499b
commit 2635af6
Showing
3 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
...ss/src/test/scala/org/alephium/ralph/lsp/access/compiler/parser/soft/IdentifierSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.alephium.ralph.lsp.access.compiler.parser.soft | ||
|
||
import org.alephium.ralph.lsp.access.compiler.parser.soft.ast.Token | ||
import org.alephium.ralph.lsp.access.compiler.parser.soft.TestParser._ | ||
import org.alephium.ralph.lsp.access.util.TestFastParse._ | ||
import org.scalatest.matchers.should.Matchers | ||
import org.scalatest.wordspec.AnyWordSpec | ||
|
||
class IdentifierSpec extends AnyWordSpec with Matchers { | ||
|
||
"disallow reserved tokens to be used as identifier" when { | ||
val reserved = | ||
Token.reserved.diff(Seq(Token.Hash)) // Remove hash because `let hash = #` is valid | ||
|
||
"tail has space" in { | ||
reserved foreach { | ||
reserved => | ||
assertIsFastParseError { | ||
parseIdentifier(s"${reserved.lexeme} ") | ||
} | ||
} | ||
} | ||
|
||
"tail is end-of-file" in { | ||
reserved foreach { | ||
reserved => | ||
assertIsFastParseError { | ||
parseIdentifier(reserved.lexeme) | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
compiler-access/src/test/scala/org/alephium/ralph/lsp/access/util/TestFastParse.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.alephium.ralph.lsp.access.util | ||
|
||
import org.alephium.ralph.error.CompilerError | ||
import org.scalatest.TryValues._ | ||
import org.scalatest.matchers.should.Matchers._ | ||
import org.scalatest.Assertion | ||
|
||
import scala.util.Try | ||
|
||
object TestFastParse { | ||
|
||
def assertIsFastParseError[A](f: => A): Assertion = | ||
Try(f) | ||
.failure | ||
.exception | ||
.getCause shouldBe a[CompilerError.FastParseError] | ||
|
||
} |