Skip to content
Closed
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
3 changes: 0 additions & 3 deletions crates/wasmparser/src/validator/names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 7 additions & 4 deletions tests/cli/component-model/naming.wast
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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"))
)
53 changes: 27 additions & 26 deletions tests/snapshots/cli/component-model/naming.wast.json
Original file line number Diff line number Diff line change
Expand Up @@ -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`"
}
]
}
12 changes: 8 additions & 4 deletions tests/snapshots/cli/component-model/naming.wast/16.print
Original file line number Diff line number Diff line change
@@ -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)))
)
6 changes: 6 additions & 0 deletions tests/snapshots/cli/component-model/naming.wast/17.print
Original file line number Diff line number Diff line change
@@ -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)))
)
Loading