diff --git a/cmd/tools/vtest-cleancode.v b/cmd/tools/vtest-cleancode.v
index a4304213e7..3a6266560d 100644
--- a/cmd/tools/vtest-cleancode.v
+++ b/cmd/tools/vtest-cleancode.v
@@ -66,6 +66,7 @@ const (
'vlib/semver/',
'vlib/strings/',
'vlib/time/',
+ 'vlib/vweb/',
]
)
diff --git a/cmd/tools/vtest-fmt.v b/cmd/tools/vtest-fmt.v
index 0ac0e32152..303433ee08 100644
--- a/cmd/tools/vtest-fmt.v
+++ b/cmd/tools/vtest-fmt.v
@@ -8,8 +8,6 @@ const (
known_failing_exceptions = [
'vlib/crypto/aes/const.v',
/* multiple narrow columns of []string turned to 1 long single column, otherwise works */
- 'vlib/vweb/vweb.v',
- /* $for method in T.methods { => $for method in T(methods) { , `return // xx` => parse expr error */
'vlib/v/gen/js/tests/life.v',
/* error: unexpected `,`, expecting ), on JS.setInterval(fn () { show(game) game = step(game) }, 500) */
'vlib/builtin/js/builtin.v',
@@ -17,11 +15,10 @@ const (
'vlib/builtin/js/jsfns_node.js.v',
'vlib/builtin/js/jsfns.js.v',
'vlib/builtin/js/jsfns_browser.js.v',
- 'vlib/builtin/bare/linuxsys_bare.v',
/* error: expr(): bad token `asm`, on `asm {}` */
- 'vlib/picoev/picoev.v',
+ 'vlib/builtin/bare/linuxsys_bare.v',
/* the fn args are removed, then `cb fn (picohttpparser.Request, mut picohttpparser.Response)` can not be reparsed */
- 'vlib/os/os.v' /* os.v - `a := [ c'/bin/sh', c'-c', byteptr(cmd.str), 0 ]` */,
+ 'vlib/picoev/picoev.v',
]
)
diff --git a/vlib/vweb/assets/assets.v b/vlib/vweb/assets/assets.v
index 8e340fb54c..2b4d783837 100644
--- a/vlib/vweb/assets/assets.v
+++ b/vlib/vweb/assets/assets.v
@@ -77,16 +77,12 @@ fn (am AssetManager) combine(asset_type string, to_file bool) string {
if to_file {
return out_file
}
- cached := os.read_file(out_file) or {
- return ''
- }
+ cached := os.read_file(out_file) or { return '' }
return cached
}
// rebuild
for asset in am.get_assets(asset_type) {
- data := os.read_file(asset.file_path) or {
- return ''
- }
+ data := os.read_file(asset.file_path) or { return '' }
out += data
}
if am.minify {
@@ -100,13 +96,9 @@ fn (am AssetManager) combine(asset_type string, to_file bool) string {
return out
}
if !os.is_dir(am.cache_dir) {
- os.mkdir(am.cache_dir) or {
- panic(err)
- }
- }
- mut file := os.create(out_file) or {
- panic(err)
+ os.mkdir(am.cache_dir) or { panic(err) }
}
+ mut file := os.create(out_file) or { panic(err) }
file.write(out.bytes())
file.close()
return out_file
diff --git a/vlib/vweb/assets/assets_test.v b/vlib/vweb/assets/assets_test.v
index 86e7aedac7..6a63d30002 100644
--- a/vlib/vweb/assets/assets_test.v
+++ b/vlib/vweb/assets/assets_test.v
@@ -20,15 +20,12 @@ fn cache_dir(test_name string) string {
fn get_test_file_path(file string) string {
path := os.join_path(base_cache_dir(), file)
-
- if ! os.is_dir(base_cache_dir()) {
+ if !os.is_dir(base_cache_dir()) {
os.mkdir_all(base_cache_dir())
}
-
- if ! os.exists(path) {
+ if !os.exists(path) {
os.write_file(path, get_test_file_contents(file))
}
-
return path
}
@@ -40,7 +37,6 @@ fn get_test_file_contents(file string) string {
'test2.css' { '.two {\n\tcolor: #996633;\n}\n' }
else { 'wibble\n' }
}
-
return contents
}
@@ -80,23 +76,19 @@ fn test_combine_css() {
mut am := assets.new_manager()
am.cache_dir = cache_dir('test_combine_css')
clean_cache_dir(am.cache_dir)
-
am.add_css(get_test_file_path('test1.css'))
am.add_css(get_test_file_path('test2.css'))
-
// TODO: How do I test non-minified, is there a "here doc" format that keeps formatting?
am.minify = true
expected := '.one { color: #336699; } .two { color: #996633; } '
actual := am.combine_css(false)
assert actual == expected
assert actual.contains(expected)
-
// Test cache path doesn't change when input files and minify setting do not.
path1 := am.combine_css(true)
clean_cache_dir(am.cache_dir)
path2 := am.combine_css(true)
assert path1 == path2
-
clean_cache_dir(am.cache_dir)
}
@@ -104,10 +96,8 @@ fn test_combine_js() {
mut am := assets.new_manager()
am.cache_dir = cache_dir('test_combine_js')
clean_cache_dir(am.cache_dir)
-
am.add_js(get_test_file_path('test1.js'))
am.add_js(get_test_file_path('test2.js'))
-
expected1 := '{"one": 1}'
expected2 := '{"two": 2}'
expected := expected1 + '\n' + expected2 + '\n'
@@ -116,20 +106,17 @@ fn test_combine_js() {
assert actual.contains(expected)
assert actual.contains(expected1)
assert actual.contains(expected2)
-
am.minify = true
clean_cache_dir(am.cache_dir)
expected3 := expected1 + ' ' + expected2 + ' '
actual2 := am.combine_js(false)
assert actual2 == expected3
assert actual2.contains(expected3)
-
// Test cache path doesn't change when input files and minify setting do not.
path1 := am.combine_js(true)
clean_cache_dir(am.cache_dir)
path2 := am.combine_js(true)
assert path1 == path2
-
clean_cache_dir(am.cache_dir)
}
@@ -141,29 +128,24 @@ fn test_include_css() {
actual := am.include_css(false)
assert actual == expected
assert actual.contains(expected)
-
// Two lines of output.
file2 := get_test_file_path('test2.css')
am.add_css(file2)
am.cache_dir = cache_dir('test_include_css')
clean_cache_dir(am.cache_dir)
-
expected2 := expected + '\n'
actual2 := am.include_css(false)
assert actual2 == expected2
assert actual2.contains(expected2)
-
// Combined output.
clean_cache_dir(am.cache_dir)
actual3 := am.include_css(true)
assert actual3.contains(expected2) == false
- assert actual3.starts_with('\n'
actual2 := am.include_js(false)
assert actual2 == expected2
assert actual2.contains(expected2)
-
// Combined output.
clean_cache_dir(am.cache_dir)
actual3 := am.include_js(true)
assert actual3.contains(expected2) == false
- assert actual3.starts_with('' {
+ } else if line == '' {
state = .html
}
if line.contains('@include ') && false {
// TODO
- pos := line.index('@include ') or {
- continue
- }
+ pos := line.index('@include ') or { continue }
file_name := line[pos + 9..]
file_path := os.join_path('templates', '${file_name}.html')
mut file_content := os.read_file(file_path) or {
@@ -90,29 +84,23 @@ _ = footer
file_content = file_content.replace("\'", '"')
lines2 := file_content.split_into_lines()
for l in lines2 {
- lines.insert(i+1, l)
+ lines.insert(i + 1, l)
}
continue
- //s.writeln(file_content)
+ // s.writeln(file_content)
} else if line.contains('@js ') {
- pos := line.index('@js') or {
- continue
- }
+ pos := line.index('@js') or { continue }
s.write('')
} else if line.contains('@css ') {
- pos := line.index('@css') or {
- continue
- }
+ pos := line.index('@css') or { continue }
s.write('')
} else if line.contains('@if ') {
s.writeln(str_end)
- pos := line.index('@if') or {
- continue
- }
+ pos := line.index('@if') or { continue }
s.writeln('if ' + line[pos + 4..] + '{')
s.writeln(str_start)
} else if line.contains('@end') {
@@ -125,16 +113,14 @@ _ = footer
s.writeln(str_start)
} else if line.contains('@for') {
s.writeln(str_end)
- pos := line.index('@for') or {
- continue
- }
+ pos := line.index('@for') or { continue }
s.writeln('for ' + line[pos + 4..] + '{')
s.writeln(str_start)
} else if state == .html && line.contains('span.') && line.ends_with('{') {
// `span.header {` => `