diff --git a/crates/wasmparser/src/validator/names.rs b/crates/wasmparser/src/validator/names.rs index 5ec899634e..ebf421c2b0 100644 --- a/crates/wasmparser/src/validator/names.rs +++ b/crates/wasmparser/src/validator/names.rs @@ -53,20 +53,17 @@ impl KebabStr { fn is_kebab_case(&self) -> bool { let mut lower = false; let mut upper = false; - let mut is_first = true; let mut has_digit = false; for c in self.chars() { match c { 'a'..='z' if !lower && !upper => lower = true, 'A'..='Z' if !lower && !upper => upper = true, - '0'..='9' if !lower && !upper && !is_first => has_digit = true, 'a'..='z' if lower => {} 'A'..='Z' if upper => {} '0'..='9' if lower || upper => has_digit = true, '-' if lower || upper || has_digit => { lower = false; upper = false; - is_first = false; has_digit = false; } _ => return false, diff --git a/tests/cli/component-model/naming.wast b/tests/cli/component-model/naming.wast index 5e7f1672ae..d86b541e86 100644 --- a/tests/cli/component-model/naming.wast +++ b/tests/cli/component-model/naming.wast @@ -29,6 +29,13 @@ "flag name `0-a-1-c` is not in kebab case" ) +(assert_invalid + (component + (type (flags "a-1-c")) + ) + "flag name `a-1-c` is not in kebab case" +) + (assert_invalid (component (type (enum "NevEr")) @@ -128,7 +135,3 @@ (import "[static]a.a" (func)) ) "import name `[static]a.a` conflicts with previous name `a`") - -(component - (type (flags "a-1-c")) -) diff --git a/tests/snapshots/cli/component-model/naming.wast.json b/tests/snapshots/cli/component-model/naming.wast.json index 93f4ebdddd..9d581d20e2 100644 --- a/tests/snapshots/cli/component-model/naming.wast.json +++ b/tests/snapshots/cli/component-model/naming.wast.json @@ -33,109 +33,110 @@ "line": 33, "filename": "naming.4.wasm", "module_type": "binary", - "text": "enum tag name `NevEr` is not in kebab case" + "text": "flag name `a-1-c` is not in kebab case" }, { "type": "assert_invalid", "line": 40, "filename": "naming.5.wasm", "module_type": "binary", - "text": "record field name `GoNnA` is not in kebab case" + "text": "enum tag name `NevEr` is not in kebab case" }, { "type": "assert_invalid", "line": 47, "filename": "naming.6.wasm", "module_type": "binary", - "text": "variant case name `GIVe` is not in kebab case" + "text": "record field name `GoNnA` is not in kebab case" }, { "type": "assert_invalid", - "line": 55, + "line": 54, "filename": "naming.7.wasm", "module_type": "binary", - "text": "function parameter name `yOu` is not in kebab case" + "text": "variant case name `GIVe` is not in kebab case" }, { "type": "assert_invalid", "line": 62, "filename": "naming.8.wasm", "module_type": "binary", - "text": "`NevEr` is not in kebab case" + "text": "function parameter name `yOu` is not in kebab case" }, { "type": "assert_invalid", "line": 69, "filename": "naming.9.wasm", "module_type": "binary", - "text": "`GonnA` is not in kebab case" + "text": "`NevEr` is not in kebab case" }, { "type": "assert_invalid", "line": 76, "filename": "naming.10.wasm", "module_type": "binary", - "text": "`lET` is not in kebab case" + "text": "`GonnA` is not in kebab case" }, { "type": "assert_invalid", "line": 83, "filename": "naming.11.wasm", "module_type": "binary", - "text": "`YoU` is not in kebab case" + "text": "`lET` is not in kebab case" }, { "type": "assert_invalid", "line": 90, "filename": "naming.12.wasm", "module_type": "binary", - "text": "`DOWn` is not in kebab case" + "text": "`YoU` is not in kebab case" }, { "type": "assert_invalid", "line": 97, "filename": "naming.13.wasm", "module_type": "binary", - "text": "character `A` is not lowercase in package name/namespace" + "text": "`DOWn` is not in kebab case" }, { "type": "assert_invalid", - "line": 103, + "line": 104, "filename": "naming.14.wasm", "module_type": "binary", - "text": "character `B` is not lowercase in package name/namespace" + "text": "character `A` is not lowercase in package name/namespace" }, { - "type": "module", - "line": 108, + "type": "assert_invalid", + "line": 110, "filename": "naming.15.wasm", - "module_type": "binary" + "module_type": "binary", + "text": "character `B` is not lowercase in package name/namespace" }, { - "type": "module_definition", - "line": 113, + "type": "module", + "line": 115, "filename": "naming.16.wasm", "module_type": "binary" }, { - "type": "assert_invalid", - "line": 119, + "type": "module_definition", + "line": 120, "filename": "naming.17.wasm", - "module_type": "binary", - "text": "import name `[method]a.a` conflicts with previous name `a`" + "module_type": "binary" }, { "type": "assert_invalid", "line": 126, "filename": "naming.18.wasm", "module_type": "binary", - "text": "import name `[static]a.a` conflicts with previous name `a`" + "text": "import name `[method]a.a` conflicts with previous name `a`" }, { - "type": "module", - "line": 132, + "type": "assert_invalid", + "line": 133, "filename": "naming.19.wasm", - "module_type": "binary" + "module_type": "binary", + "text": "import name `[static]a.a` conflicts with previous name `a`" } ] } \ No newline at end of file diff --git a/tests/snapshots/cli/component-model/naming.wast/16.print b/tests/snapshots/cli/component-model/naming.wast/16.print index 9e722ade6c..bf4c7d129d 100644 --- a/tests/snapshots/cli/component-model/naming.wast/16.print +++ b/tests/snapshots/cli/component-model/naming.wast/16.print @@ -1,6 +1,10 @@ (component - (import "a" (type $a (;0;) (sub resource))) - (type (;1;) (own $a)) - (type (;2;) (func (result 1))) - (import "[constructor]a" (func (;0;) (type 2))) + (type (;0;) + (instance) + ) + (import "a:b/c" (instance (;0;) (type 0))) + (type (;1;) + (instance) + ) + (import "a1:b1/c" (instance (;1;) (type 1))) ) diff --git a/tests/snapshots/cli/component-model/naming.wast/17.print b/tests/snapshots/cli/component-model/naming.wast/17.print new file mode 100644 index 0000000000..9e722ade6c --- /dev/null +++ b/tests/snapshots/cli/component-model/naming.wast/17.print @@ -0,0 +1,6 @@ +(component + (import "a" (type $a (;0;) (sub resource))) + (type (;1;) (own $a)) + (type (;2;) (func (result 1))) + (import "[constructor]a" (func (;0;) (type 2))) +)