Skip to content

Commit 4f05ffc

Browse files
authored
test(unikraft/app): Add unit tests for normalize.go (#2695)
Reviewed-by: Cezar Craciunoiu <cezar.craciunoiu@unikraft.com> Approved-by: Cezar Craciunoiu <cezar.craciunoiu@unikraft.com>
2 parents 650ea40 + 12e211c commit 4f05ffc

1 file changed

Lines changed: 117 additions & 0 deletions

File tree

‎unikraft/app/normalize_test.go‎

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
// Copyright (c) 2022, Unikraft GmbH and The KraftKit Authors.
3+
// Licensed under the BSD-3-Clause License (the "License").
4+
// You may not use this file except in compliance with the License.
5+
package app
6+
7+
import (
8+
"testing"
9+
)
10+
11+
func Test_normalizeProjectName(t *testing.T) {
12+
tests := []struct {
13+
name string
14+
input string
15+
want string
16+
}{
17+
{
18+
name: "lowercase passthrough",
19+
input: "myapp",
20+
want: "myapp",
21+
},
22+
{
23+
name: "uppercase converted to lowercase",
24+
input: "MyApp",
25+
want: "myapp",
26+
},
27+
{
28+
name: "all uppercase",
29+
input: "MYAPP",
30+
want: "myapp",
31+
},
32+
{
33+
name: "with hyphen",
34+
input: "my-app",
35+
want: "my-app",
36+
},
37+
{
38+
name: "with underscore",
39+
input: "my_app",
40+
want: "my_app",
41+
},
42+
{
43+
name: "spaces removed",
44+
input: "my app",
45+
want: "myapp",
46+
},
47+
{
48+
name: "special characters removed",
49+
input: "my.app!",
50+
want: "myapp",
51+
},
52+
{
53+
name: "leading underscore trimmed",
54+
input: "_myapp",
55+
want: "myapp",
56+
},
57+
{
58+
name: "leading hyphen trimmed",
59+
input: "-myapp",
60+
want: "myapp",
61+
},
62+
{
63+
name: "multiple leading underscores and hyphens trimmed",
64+
input: "--__myapp",
65+
want: "myapp",
66+
},
67+
{
68+
name: "digits preserved",
69+
input: "app123",
70+
want: "app123",
71+
},
72+
{
73+
name: "mixed case with digits and special chars",
74+
input: "My App 123!",
75+
want: "myapp123",
76+
},
77+
{
78+
name: "empty string",
79+
input: "",
80+
want: "",
81+
},
82+
{
83+
name: "only special characters",
84+
input: "!!!",
85+
want: "",
86+
},
87+
{
88+
name: "only leading separators",
89+
input: "---",
90+
want: "",
91+
},
92+
{
93+
name: "uppercase with digits",
94+
input: "MyApp123",
95+
want: "myapp123",
96+
},
97+
{
98+
name: "trailing hyphen preserved",
99+
input: "myapp-",
100+
want: "myapp-",
101+
},
102+
{
103+
name: "trailing underscore preserved",
104+
input: "myapp_",
105+
want: "myapp_",
106+
},
107+
}
108+
109+
for _, tt := range tests {
110+
t.Run(tt.name, func(t *testing.T) {
111+
got := normalizeProjectName(tt.input)
112+
if got != tt.want {
113+
t.Errorf("normalizeProjectName(%q) = %q, want %q", tt.input, got, tt.want)
114+
}
115+
})
116+
}
117+
}

0 commit comments

Comments
 (0)