diff options
Diffstat (limited to 'v_windows/v/cmd/tools/vdoc/tests')
10 files changed, 191 insertions, 0 deletions
diff --git a/v_windows/v/cmd/tools/vdoc/tests/testdata/basic/main.comments.out b/v_windows/v/cmd/tools/vdoc/tests/testdata/basic/main.comments.out new file mode 100644 index 0000000..326f0c5 --- /dev/null +++ b/v_windows/v/cmd/tools/vdoc/tests/testdata/basic/main.comments.out @@ -0,0 +1,7 @@ +module main + +const ( + source_root = 'temp' +) +fn funky() + funky - comment for function below
\ No newline at end of file diff --git a/v_windows/v/cmd/tools/vdoc/tests/testdata/basic/main.out b/v_windows/v/cmd/tools/vdoc/tests/testdata/basic/main.out new file mode 100644 index 0000000..08fe504 --- /dev/null +++ b/v_windows/v/cmd/tools/vdoc/tests/testdata/basic/main.out @@ -0,0 +1,6 @@ +module main + +const ( + source_root = 'temp' +) +fn funky()
\ No newline at end of file diff --git a/v_windows/v/cmd/tools/vdoc/tests/testdata/basic/main.v b/v_windows/v/cmd/tools/vdoc/tests/testdata/basic/main.v new file mode 100644 index 0000000..9cb66e3 --- /dev/null +++ b/v_windows/v/cmd/tools/vdoc/tests/testdata/basic/main.v @@ -0,0 +1,8 @@ +pub const ( + source_root = 'temp' +) + +// funky - comment for function below +pub fn funky() { + println('hi') +} diff --git a/v_windows/v/cmd/tools/vdoc/tests/testdata/multiline/main.comments.out b/v_windows/v/cmd/tools/vdoc/tests/testdata/multiline/main.comments.out new file mode 100644 index 0000000..793abf1 --- /dev/null +++ b/v_windows/v/cmd/tools/vdoc/tests/testdata/multiline/main.comments.out @@ -0,0 +1,9 @@ +module main + +fn a1() + normal comment +fn a2() + this should be merged into the same line +fn a3() + This should be its own parapgraph, because it ends with a dot. + This should be another paragraph. diff --git a/v_windows/v/cmd/tools/vdoc/tests/testdata/multiline/main.out b/v_windows/v/cmd/tools/vdoc/tests/testdata/multiline/main.out new file mode 100644 index 0000000..4a3c36b --- /dev/null +++ b/v_windows/v/cmd/tools/vdoc/tests/testdata/multiline/main.out @@ -0,0 +1,5 @@ +module main + +fn a1() +fn a2() +fn a3() diff --git a/v_windows/v/cmd/tools/vdoc/tests/testdata/multiline/main.v b/v_windows/v/cmd/tools/vdoc/tests/testdata/multiline/main.v new file mode 100644 index 0000000..840ca43 --- /dev/null +++ b/v_windows/v/cmd/tools/vdoc/tests/testdata/multiline/main.v @@ -0,0 +1,16 @@ +// normal comment +pub fn a1() { + println('hi') +} + +// this should be merged +// into the same line +pub fn a2() { + println('hi') +} + +// This should be its own parapgraph, because it ends with a dot. +// This should be another paragraph. +pub fn a3() { + println('hi') +} diff --git a/v_windows/v/cmd/tools/vdoc/tests/testdata/newlines/main.comments.out b/v_windows/v/cmd/tools/vdoc/tests/testdata/newlines/main.comments.out new file mode 100644 index 0000000..f3ee942 --- /dev/null +++ b/v_windows/v/cmd/tools/vdoc/tests/testdata/newlines/main.comments.out @@ -0,0 +1,22 @@ +module main + +fn funky() + hello + + empty line + newline using a full stop. + ```v + code + ``` + + test + ==== + - foo + - bar + # test + ########### deep test + #a shouldnt have a newline test + + | foo bar | yes | + |-----------|--------| + | working | yup |
\ No newline at end of file diff --git a/v_windows/v/cmd/tools/vdoc/tests/testdata/newlines/main.out b/v_windows/v/cmd/tools/vdoc/tests/testdata/newlines/main.out new file mode 100644 index 0000000..02bcce9 --- /dev/null +++ b/v_windows/v/cmd/tools/vdoc/tests/testdata/newlines/main.out @@ -0,0 +1,3 @@ +module main + +fn funky()
\ No newline at end of file diff --git a/v_windows/v/cmd/tools/vdoc/tests/testdata/newlines/main.v b/v_windows/v/cmd/tools/vdoc/tests/testdata/newlines/main.v new file mode 100644 index 0000000..8d2bf90 --- /dev/null +++ b/v_windows/v/cmd/tools/vdoc/tests/testdata/newlines/main.v @@ -0,0 +1,23 @@ +// hello +// +// empty line +// newline using a full stop. +// ```v +// code +// ``` +// +// test +// ==== +// - foo +// - bar +// # test +// ########### deep test +// #a shouldnt have a newline +// test +// +// | foo bar | yes | +// |-----------|--------| +// | working | yup | +pub fn funky() { + println('hi') +} diff --git a/v_windows/v/cmd/tools/vdoc/tests/vdoc_file_test.v b/v_windows/v/cmd/tools/vdoc/tests/vdoc_file_test.v new file mode 100644 index 0000000..254337c --- /dev/null +++ b/v_windows/v/cmd/tools/vdoc/tests/vdoc_file_test.v @@ -0,0 +1,92 @@ +import os +import rand +import term +import v.util.vtest +import v.util.diff + +const vexe = @VEXE + +const vroot = @VMODROOT + +const diff_cmd = find_diff_cmd() + +fn find_diff_cmd() string { + return diff.find_working_diff_command() or { '' } +} + +fn test_vet() ? { + os.setenv('VCOLORS', 'never', true) + os.chdir(vroot) ? + test_dir := 'cmd/tools/vdoc/tests/testdata' + main_files := get_main_files_in_dir(test_dir) + fails := check_path(vexe, test_dir, main_files) + assert fails == 0 +} + +fn get_main_files_in_dir(dir string) []string { + mut mfiles := os.walk_ext(dir, '.v') + mfiles.sort() + return mfiles +} + +fn check_path(vexe string, dir string, tests []string) int { + mut nb_fail := 0 + paths := vtest.filter_vtest_only(tests, basepath: vroot) + for path in paths { + program := path + print(path + ' ') + res := os.execute('$vexe doc $program') + if res.exit_code < 0 { + panic(res.output) + } + mut expected := os.read_file(program.replace('main.v', 'main.out')) or { panic(err) } + expected = clean_line_endings(expected) + found := clean_line_endings(res.output) + if expected != found { + print_compare(expected, found) + } + + res_comments := os.execute('$vexe doc -comments $program') + if res_comments.exit_code < 0 { + panic(res_comments.output) + } + mut expected_comments := os.read_file(program.replace('main.v', 'main.comments.out')) or { + panic(err) + } + expected_comments = clean_line_endings(expected_comments) + found_comments := clean_line_endings(res_comments.output) + if expected_comments != found_comments { + print_compare(expected_comments, found_comments) + } + + if expected == found && expected_comments == found_comments { + println(term.green('OK')) + } else { + nb_fail++ + } + } + return nb_fail +} + +fn print_compare(expected string, found string) { + println(term.red('FAIL')) + println('============') + println('expected:') + println(expected) + println('============') + println('found:') + println(found) + println('============\n') + println('diff:') + println(diff.color_compare_strings(diff_cmd, rand.ulid(), found, expected)) + println('============\n') +} + +fn clean_line_endings(s string) string { + mut res := s.trim_space() + res = res.replace(' \n', '\n') + res = res.replace(' \r\n', '\n') + res = res.replace('\r\n', '\n') + res = res.trim('\n') + return res +} |