Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WX-1145 Fix minor regression introduced in WDL 1.1 foundation #7153

Merged
merged 3 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ object LanguageFactoryUtil {
}

val firstCodeLine = fileWithoutInitialWhitespace.headOption.map(_.dropWhile(_.isWhitespace))
firstCodeLine.exists { line => startsWithOptions.contains(line) }
firstCodeLine.exists { line => startsWithOptions.contains(line.trim) }
}

def chooseFactory(workflowSource: WorkflowSource, wsfc: WorkflowSourceFilesCollection): ErrorOr[LanguageFactory] = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package cromwell.languages.util

import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers

class LooksParseableSpec extends AnyFlatSpec with Matchers {
behavior of "simpleLooksParseable"

it should "work with `version 1.0` followed by whitespace" in {

val source =
"""
|version 1.0
|# Programmer warning: make sure your editor does not trim the whitespace in the line above.
|""".stripMargin

LanguageFactoryUtil.simpleLooksParseable(List("version 1.0"), List("#"))(source) shouldBe true
}

it should "work with `version 1.0` preceded by whitespace" in {

val source =
"""
| version 1.0
|# Programmer warning: make sure your editor does not trim the whitespace in the line above.
|""".stripMargin

LanguageFactoryUtil.simpleLooksParseable(List("version 1.0"), List("#"))(source) shouldBe true
}

it should "work with `version 1.0` surrounded by whitespace" in {

val source =
"""
| version 1.0
|# Programmer warning: make sure your editor does not trim the whitespace in the line above.
|""".stripMargin

LanguageFactoryUtil.simpleLooksParseable(List("version 1.0"), List("#"))(source) shouldBe true
}

it should "work with `version 1.0` surrounded by whitespace on all sides" in {

val source =
"""
|
| version 1.0
|
|# Programmer warning: make sure your editor does not trim the whitespace in the line above.
|""".stripMargin

LanguageFactoryUtil.simpleLooksParseable(List("version 1.0"), List("#"))(source) shouldBe true
}

// This test technically contradicts the spec [0] but there is better hope of receiving a useful
// error if we try & fail to parse as 1.0, than if we fall back to the server default, `draft-2`
// > From draft-3 forward, the first line of all WDL files must be a version statement
// [0] https://github.com/openwdl/wdl/blob/main/versions/1.0/SPEC.md#versioning
it should "work with `version 1.0` surrounded by comments" in {

val source =
"""
|# My WDL does a cool thing
|version 1.0
|# Here we go...
|""".stripMargin

LanguageFactoryUtil.simpleLooksParseable(List("version 1.0"), List("#"))(source) shouldBe true
}

it should "reject Chris's idea of a version declaration" in {

val source =
"""
|# Thank goodness this WDL is not version 1.1!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed!

|""".stripMargin

LanguageFactoryUtil.simpleLooksParseable(List("version 1.0"), List("#"))(source) shouldBe false
}

}