Fixed switch in test and readme.

This commit is contained in:
Marvin Blum
2015-10-28 17:50:46 +01:00
parent a64bef135d
commit bba215cd8d
6 changed files with 16 additions and 17 deletions

View File

@@ -90,13 +90,11 @@ each allUnits { // foreach, iterates over all units in this case
// element is available as _x here // element is available as _x here
} }
switch x { switch x { // there is no "break" in SQF
case 1: case 1:
// ... // ...
break;
case 2: case 2:
// ... // ...
break;
default: default:
// ... // ...
} }

View File

@@ -1,6 +1,4 @@
var array = [1, 2, 3]; switch x {
var x = array[0]; case 1:
x = 1;
if array[(1-1)+10/10] == 2 {
foo();
} }

View File

@@ -49,7 +49,10 @@ func TestParserForeach(t *testing.T) {
} }
func TestParserSwitch(t *testing.T) { func TestParserSwitch(t *testing.T) {
got := getCompiled(t, "test/tokenizer_switch.asl")
want := "switch (x) do {\r\ncase 1:\r\n{\r\nx = 1;\r\n};\r\ncase 2:\r\n{\r\nx = 2;\r\n};\r\ndefault:\r\n{\r\nx = 3;\r\n};\r\n};\r\n"
equal(t, got, want)
} }
func TestParserFunction(t *testing.T) { func TestParserFunction(t *testing.T) {

View File

@@ -47,7 +47,7 @@ func TestTokenizerForach(t *testing.T) {
func TestTokenizerSwitch(t *testing.T) { func TestTokenizerSwitch(t *testing.T) {
got := getTokens(t, "test/tokenizer_switch.asl") got := getTokens(t, "test/tokenizer_switch.asl")
want := []string{"switch", "x", "{", "case", "1", ":", "x", "=", "1", ";", "break", ";", "case", "2", ":", "x", "=", "2", ";", "break", ";", "default", ":", "x", "=", "3", ";", "}"} want := []string{"switch", "x", "{", "case", "1", ":", "x", "=", "1", ";", "case", "2", ":", "x", "=", "2", ";", "default", ":", "x", "=", "3", ";", "}"}
compareLength(t, &got, &want) compareLength(t, &got, &want)
compareTokens(t, &got, &want) compareTokens(t, &got, &want)

View File

@@ -22,11 +22,13 @@ type ASLFile struct {
newname string newname string
} }
var recursive bool = false var (
var pretty bool = false recursive bool = false
var exit bool = false pretty bool = false
var aslFiles []ASLFile exit bool = false
var inDir string aslFiles []ASLFile
inDir string
)
func usage() { func usage() {
fmt.Println("Usage: asl [-v|-r|-pretty|--help] <input directory> <output directory>\n") fmt.Println("Usage: asl [-v|-r|-pretty|--help] <input directory> <output directory>\n")

View File

@@ -1,10 +1,8 @@
switch x { switch x {
case 1: case 1:
x = 1; x = 1;
break;
case 2: case 2:
x = 2; x = 2;
break;
default: default:
x = 3; x = 3;
} }