Skip to content

Commit

Permalink
move test data in to tests to work in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-ward committed May 22, 2024
1 parent e64f9fe commit c8bb649
Show file tree
Hide file tree
Showing 11 changed files with 176 additions and 75 deletions.
190 changes: 176 additions & 14 deletions src/fmt/fmt_test.v
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module main

import os
import time

fn print_lines(lines []string) {
println(' ')
println('-------------')
Expand All @@ -8,9 +11,28 @@ fn print_lines(lines []string) {
}
}

fn temp_file_name() string {
dir := os.temp_dir()
file := '${dir}/t${time.ticks()}'
return file
}

fn to_tmp_file(data []string) string {
file := temp_file_name()
os.write_file(file, data.join_lines()) or { panic('error') }
return file
}

fn test_basic_wrap() {
println(@METHOD)
output := run_fmt(['fmt', '-w', '30', 'testdata/simple.txt'])
input := [
'Now is the time for all good men to come to the aid of their country.',
'',
'Now is the time for all good men to come to the aid of their country.',
]
tmp := to_tmp_file(input)
output := run_fmt(['fmt', '-w', '30', tmp])
os.rm(tmp)!
// print_lines(output)
expected := [
'Now is the time for all good',
Expand All @@ -26,7 +48,26 @@ fn test_basic_wrap() {

fn test_narrow_to_formatted() {
println(@METHOD)
output := run_fmt(['fmt', 'testdata/narrow.txt'])
input := [
'Hello World',
'',
'Hi there!',
'How are you?',
'',
'Just do-it.',
'Believe it.',
'',
'banana,',
'papaya,',
'mango',
'',
'Much ado about nothing.',
'He he he.',
'Adios amigo.',
]
tmp := to_tmp_file(input)
output := run_fmt(['fmt', tmp])
os.rm(tmp)!
// print_lines(output)
expected := [
'Hello World',
Expand All @@ -44,7 +85,16 @@ fn test_narrow_to_formatted() {

fn test_line_indents_denote_new_paragraph() {
println(@METHOD)
output := run_fmt(['fmt', '-w', '35', 'testdata/basic_indent.txt'])
input := [
'This is a single line paragraph',
' because this line has a different indent',
'',
'Otherwise these other lines comprise a simple',
'multline paragraph.',
]
tmp := to_tmp_file(input)
output := run_fmt(['fmt', '-w', '35', tmp])
os.rm(tmp)!
expected := [
'This is a single line paragraph',
' because this line has a',
Expand All @@ -59,7 +109,17 @@ fn test_line_indents_denote_new_paragraph() {

fn test_numbered_list_no_options() {
println(@METHOD)
output := run_fmt(['fmt', 'testdata/list.txt'])
input := [
'A list of items',
'',
' 1. Now is the time for all good men to come to the aid of their country.',
' 2. Now is the time for all good men to come to the aid of their country.',
' 3. Now is the time for all good men to come to the aid of their country.',
' 4. Now is the time for all good men to come to the aid of their country.',
]
tmp := to_tmp_file(input)
output := run_fmt(['fmt', tmp])
os.rm(tmp)!
// print_lines(output)
expected := [
'A list of items',
Expand All @@ -75,7 +135,17 @@ fn test_numbered_list_no_options() {

fn test_numbered_list_w_40() {
println(@METHOD)
output := run_fmt(['fmt', '-w', '40', 'testdata/list.txt'])
input := [
'A list of items',
'',
' 1. Now is the time for all good men to come to the aid of their country.',
' 2. Now is the time for all good men to come to the aid of their country.',
' 3. Now is the time for all good men to come to the aid of their country.',
' 4. Now is the time for all good men to come to the aid of their country.',
]
tmp := to_tmp_file(input)
output := run_fmt(['fmt', '-w', '40', tmp])
os.rm(tmp)!
// print_lines(output)
expected := [
'A list of items',
Expand All @@ -94,7 +164,24 @@ fn test_numbered_list_w_40() {

fn test_split_only() {
println(@METHOD)
output := run_fmt(['fmt', '-s', 'testdata/lorum_ipsum.txt'])
input := [
'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Curabitur dignissim',
'venenatis pede. Quisque dui dui, ultricies ut, facilisis non, pulvinar non. Duis quis arcu a purus volutpat iaculis. Morbi id dui in diam ornare',
'dictum. Praesent consectetuer vehicula ipsum. Praesent tortor massa, congue et,',
'ornare in, posuere eget, pede.',
'',
'Vivamus rhoncus. Quisque lacus. In hac habitasse platea dictumst. Nullam mauris',
'tellus, sollicitudin non, semper eget, sodales non, pede. Phasellus varius',
'ullamcorper libero. Fusce ipsum lorem, iaculis nec, vulputate vitae, suscipit',
'vel, tortor. Cras varius.',
'',
'Nullam fringilla pellentesque orci. Nulla eu ante pulvinar velit rhoncus',
'lacinia. Morbi fringilla lacus quis arcu. Vestibulum sem quam, dapibus in,',
'fringilla ut, venenatis ut, neque.',
]
tmp := to_tmp_file(input)
output := run_fmt(['fmt', '-s', tmp])
os.rm(tmp)!
expected := [
'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Curabitur',
'dignissim',
Expand All @@ -120,7 +207,18 @@ fn test_split_only() {

fn test_indents_no_blank_lines() {
println(@METHOD)
output := run_fmt(['fmt', 'testdata/poem.txt'])
input := [
'Love is patient, love is kind. It does not envy,',
' it does not boast, it is not proud. It is not rude,',
' it is not self-seeking, it is not easily angered, ',
'it keeps no record of wrongs. Love does not delight ',
'in evil but rejoices with the truth. It always protects,',
' always trusts, always hopes, always perseveres. ',
'Love never fails.',
]
tmp := to_tmp_file(input)
output := run_fmt(['fmt', tmp])
os.rm(tmp)!
expected := [
'Love is patient, love is kind. It does not envy,',
' it does not boast, it is not proud. It is not rude, it is not',
Expand All @@ -135,7 +233,18 @@ fn test_indents_no_blank_lines() {

fn test_prefix_str_option() {
println(@METHOD)
output := run_fmt(['fmt', '-p', '> ', 'testdata/prefix.txt'])
input := [
'Prefix lines test',
'',
'> Effects present letters inquiry no an removed or friends. Desire behind latter me though in. ',
'> Supposing shameless am he engrossed up additions. My possible peculiar together to. ',
'',
'> Desire so better am cannot he up before points. Remember mistaken opinions it pleasure of debating. ',
'> Court front maids forty if aware their at. Chicken use are pressed removed.',
]
tmp := to_tmp_file(input)
output := run_fmt(['fmt', '-p', '> ', tmp])
os.rm(tmp)!
expected := [
'Prefix lines test',
'',
Expand All @@ -153,8 +262,12 @@ fn test_prefix_str_option() {

fn test_uniform_spacing_option() {
println(@METHOD)
input := [
'venenatis pede. Quisque dui dui, ultricies ut, facilisis non, pulvinar non. Duis quis arcu a purus volutpat iaculis. Morbi id dui in diam ornare',
]
tmp := to_tmp_file(input)
// non-uniform case
output1 := run_fmt(['fmt', 'testdata/not_uniform_spacing.txt'])
output1 := run_fmt(['fmt', tmp])
expected1 := [
'venenatis pede. Quisque dui dui, ultricies ut, facilisis non,',
'pulvinar non. Duis quis arcu a purus volutpat iaculis. Morbi id dui',
Expand All @@ -163,7 +276,8 @@ fn test_uniform_spacing_option() {
assert output1 == expected1

// uniform spacing case
output2 := run_fmt(['fmt', '-u', 'testdata/not_uniform_spacing.txt'])
output2 := run_fmt(['fmt', '-u', tmp])
os.rm(tmp)!
expected2 := [
'venenatis pede. Quisque dui dui, ultricies ut, facilisis non, pulvinar non.',
'Duis quis arcu a purus volutpat iaculis. Morbi id dui in diam ornare',
Expand All @@ -173,7 +287,18 @@ fn test_uniform_spacing_option() {

fn test_uniform_spacing_with_prefix_and_width() {
println(@METHOD)
output := run_fmt(['fmt', '-u', '-p', '> ', '-w', '30', 'testdata/prefix.txt'])
input := [
'Prefix lines test',
'',
'> Effects present letters inquiry no an removed or friends. Desire behind latter me though in. ',
'> Supposing shameless am he engrossed up additions. My possible peculiar together to. ',
'',
'> Desire so better am cannot he up before points. Remember mistaken opinions it pleasure of debating. ',
'> Court front maids forty if aware their at. Chicken use are pressed removed.',
]
tmp := to_tmp_file(input)
output := run_fmt(['fmt', '-u', '-p', '> ', '-w', '30', tmp])
os.rm(tmp)!
expected := [
'> Prefix lines test',
'',
Expand All @@ -199,7 +324,14 @@ fn test_uniform_spacing_with_prefix_and_width() {

fn test_crown_and_uniform_options() {
println(@METHOD)
output := run_fmt(['fmt', '-c', '-u', 'testdata/crown.txt'])
input := [
'By default, blank lines, spaces between words, and indentation are preserved in the output;',
' successive input lines with different indentation are not joined; tabs are expanded on input and',
'introduced on output.',
]
tmp := to_tmp_file(input)
output := run_fmt(['fmt', '-c', '-u', tmp])
os.rm(tmp)!
expected := [
'By default, blank lines, spaces between words, and indentation are',
' preserved in the output; successive input lines with different',
Expand All @@ -211,7 +343,14 @@ fn test_crown_and_uniform_options() {

fn test_tagged_and_width_options() {
println(@METHOD)
output := run_fmt(['fmt', '-t', '-w', '40', 'testdata/simple.txt'])
input := [
'Now is the time for all good men to come to the aid of their country.',
'',
'Now is the time for all good men to come to the aid of their country.',
]
tmp := to_tmp_file(input)
output := run_fmt(['fmt', '-t', '-w', '40', tmp])
os.rm(tmp)!
expected := [
'Now is the time for all good men to come',
' to the aid of their country.',
Expand All @@ -224,7 +363,12 @@ fn test_tagged_and_width_options() {

fn test_unicode_handling() {
println(@METHOD)
output := run_fmt(['fmt', '-w', '40', 'testdata/unicode.txt'])
input := [
"I can do without ⑰ lobsters, you know. Come on!' So they ⼘≺↩⌝⚙⠃ couldn't get them out again. The Mock Turtle went on again:-- 'I didn't mean it!' Ⓡpleaded.",
]
tmp := to_tmp_file(input)
output := run_fmt(['fmt', '-w', '40', tmp])
os.rm(tmp)!
expected := [
'I can do without ⑰ lobsters, you know.',
"Come on!' So they ⼘≺↩⌝⚙⠃ couldn't get",
Expand All @@ -233,3 +377,21 @@ fn test_unicode_handling() {
]
assert output == expected
}

fn test_unicode__tab_handling() {
println(@METHOD)
input := [
"I can do without ⑰ lobsters, \tyou know. Come on!' So they ⼘≺↩⌝⚙⠃ couldn't get them out again. The Mock Turtle went on again:-- 'I didn't mean it!' Ⓡpleaded.",
]
tmp := to_tmp_file(input)
output := run_fmt(['fmt', '-w', '40', tmp])
os.rm(tmp)!
expected := [
'I can do without ⑰ lobsters, you',
"know. Come on!' So they ⼘≺↩⌝⚙⠃ couldn't",
'get them out again. The Mock Turtle went',
"on again:-- 'I didn't mean it!'",
'Ⓡpleaded.',
]
assert output == expected
}
5 changes: 0 additions & 5 deletions src/fmt/testdata/basic_indent.txt

This file was deleted.

3 changes: 0 additions & 3 deletions src/fmt/testdata/crown.txt

This file was deleted.

6 changes: 0 additions & 6 deletions src/fmt/testdata/list.txt

This file was deleted.

13 changes: 0 additions & 13 deletions src/fmt/testdata/lorum_ipsum.txt

This file was deleted.

15 changes: 0 additions & 15 deletions src/fmt/testdata/narrow.txt

This file was deleted.

1 change: 0 additions & 1 deletion src/fmt/testdata/not_uniform_spacing.txt

This file was deleted.

7 changes: 0 additions & 7 deletions src/fmt/testdata/poem.txt

This file was deleted.

7 changes: 0 additions & 7 deletions src/fmt/testdata/prefix.txt

This file was deleted.

3 changes: 0 additions & 3 deletions src/fmt/testdata/simple.txt

This file was deleted.

1 change: 0 additions & 1 deletion src/fmt/testdata/unicode.txt

This file was deleted.

0 comments on commit c8bb649

Please sign in to comment.