-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add stringToName special case for all-underscores strings
Before, parsing the following PVL program would give an assertion error, since it would attempt to build a preferred name with no parts: ``` void ___() { } ``` It now gets a preferred name with one part, the string "___". Also adds a unit test for stringToName.
- Loading branch information
1 parent
b5b15bc
commit d9cf473
Showing
2 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
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
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,35 @@ | ||
package origin | ||
|
||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.prop.TableDrivenPropertyChecks.{Table, forAll} | ||
import vct.col.origin.SourceName | ||
|
||
class OriginSpec extends AnyFlatSpec { | ||
behavior of "SourceName.stringToName" | ||
|
||
it should "come up with a reasonable name for any identifier" in { | ||
val cases = Table( | ||
("string", "snake", "camel"), | ||
("foo", "foo", "foo"), | ||
("foo_bar", "foo_bar", "fooBar"), | ||
("foo_bar_baz", "foo_bar_baz", "fooBarBaz"), | ||
("montAiguille", "mont_aiguille", "montAiguille"), | ||
("GERVANNE", "gervanne", "gervanne"), | ||
("VeRnAiSoN", "ve_rn_ai_so_n", "veRnAiSoN"), | ||
("_", "_", "_"), | ||
("___", "___", "___"), | ||
("_a", "a", "a"), | ||
("a_", "a", "a"), | ||
("a_b_", "a_b", "aB"), | ||
("_a_b", "a_b", "aB"), | ||
("do__ob", "do_ob", "doOb"), | ||
("do____ob", "do_ob", "doOb"), | ||
) | ||
|
||
forAll(cases) { (string, snake, camel) => | ||
val name = SourceName.stringToName(string) | ||
assert(name.snake == snake) | ||
assert(name.camel == camel) | ||
} | ||
} | ||
} |