From 0447b3e4cc4ac204b1fb7e555f897b775a498e79 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Wed, 13 Oct 2021 22:03:28 +0200 Subject: [PATCH] remove testcase that attempted to check invalid %import syntax. we only allow unquoted names, without filename suffix, in %import. --- compiler/src/prog8/compiler/ModuleImporter.kt | 4 +++- .../test/TestCompilerOnImportsAndIncludes.kt | 23 ------------------- .../fixtures/importFromSameFolder_strLit.p8 | 9 -------- compilerAst/test/TestProg8Parser.kt | 1 - 4 files changed, 3 insertions(+), 34 deletions(-) delete mode 100644 compiler/test/fixtures/importFromSameFolder_strLit.p8 diff --git a/compiler/src/prog8/compiler/ModuleImporter.kt b/compiler/src/prog8/compiler/ModuleImporter.kt index 50dbb67a4..ae03b401b 100644 --- a/compiler/src/prog8/compiler/ModuleImporter.kt +++ b/compiler/src/prog8/compiler/ModuleImporter.kt @@ -69,8 +69,10 @@ class ModuleImporter(private val program: Program, } private fun executeImportDirective(import: Directive, importingModule: Module?): Module? { - if(import.directive!="%import" || import.args.size!=1 || import.args[0].name==null) + if(import.directive!="%import" || import.args.size!=1) throw SyntaxError("invalid import directive", import.position) + if(!import.args[0].str.isNullOrEmpty() || import.args[0].name==null) + throw SyntaxError("%import requires unquoted module name", import.position) val moduleName = import.args[0].name!! if("$moduleName.p8" == import.position.file) throw SyntaxError("cannot import self", import.position) diff --git a/compiler/test/TestCompilerOnImportsAndIncludes.kt b/compiler/test/TestCompilerOnImportsAndIncludes.kt index 31015d253..dddd9df4b 100644 --- a/compiler/test/TestCompilerOnImportsAndIncludes.kt +++ b/compiler/test/TestCompilerOnImportsAndIncludes.kt @@ -46,29 +46,6 @@ class TestCompilerOnImportsAndIncludes { assertEquals("main", strLits[0].definingScope.name) assertEquals("foo", strLits[1].definingScope.name) } - - @Test - @Disabled("TODO: why would we not accept string literals as argument to %import?") - fun testImportFromSameFolder_strLit() { - val filepath = assumeReadableFile(fixturesDir,"importFromSameFolder_strLit.p8") - val imported = assumeReadableFile(fixturesDir, "foo_bar.p8") - - val platform = Cx16Target - val result = compileFile(platform, optimize = false, fixturesDir, filepath.name) - .assertSuccess() - - val program = result.programAst - val startSub = program.entrypoint - val strLits = startSub.statements - .filterIsInstance() - .map { it.args[0] as IdentifierReference } - .map { it.targetVarDecl(program)!!.value as StringLiteralValue } - - assertEquals("main.bar", strLits[0].value) - assertEquals("foo.bar", strLits[1].value) - assertEquals("main", strLits[0].definingScope.name) - assertEquals("foo", strLits[1].definingScope.name) - } } @Nested diff --git a/compiler/test/fixtures/importFromSameFolder_strLit.p8 b/compiler/test/fixtures/importFromSameFolder_strLit.p8 deleted file mode 100644 index 0f75c437f..000000000 --- a/compiler/test/fixtures/importFromSameFolder_strLit.p8 +++ /dev/null @@ -1,9 +0,0 @@ -%import textio -%import "foo_bar.p8" -main { - str myBar = "main.bar" - sub start() { - txt.print(myBar) - txt.print(foo.bar) - } -} diff --git a/compilerAst/test/TestProg8Parser.kt b/compilerAst/test/TestProg8Parser.kt index 3a9ede625..4fca5034c 100644 --- a/compilerAst/test/TestProg8Parser.kt +++ b/compilerAst/test/TestProg8Parser.kt @@ -344,7 +344,6 @@ class TestProg8Parser { * TODO: this test is testing way too much at once */ @Test - //@Disabled("TODO: fix .position of nodes below Module - step 8, 'refactor AST gen'") fun `of non-root Nodes parsed from a string`() { val srcText = """ %zeropage basicsafe ; DirectiveArg directly inherits from Node - neither an Expression nor a Statement..?