Skip to content

Commit

Permalink
remove .json files, force json to be created every time, fix delete
Browse files Browse the repository at this point in the history
  • Loading branch information
JalonSolov committed Aug 14, 2024
1 parent 793183a commit 94bd142
Show file tree
Hide file tree
Showing 118 changed files with 71 additions and 20,434 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ z
#Intellij IDEA
.idea/
*.iml
**/*.json
17 changes: 13 additions & 4 deletions fn_call.v
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,20 @@ fn (mut app App) call_expr(call CallExpr) {

if fun is Ident && fun.name == 'delete' {
arg0 := call.args[0]
if arg0 is Ident {
app.gen('${arg0.name}.${fun.name}(')
app.expr(call.args[1])
app.genln(')')
match arg0 {
Ident {
app.gen('${arg0.name}')
}
SelectorExpr {
app.expr(arg0)
}
else {
app.gen('// UNHANDLED delete type')
}
}
app.gen('.${fun.name}(')
app.expr(call.args[1])
app.genln(')')
return
}

Expand Down
56 changes: 27 additions & 29 deletions main.v
Original file line number Diff line number Diff line change
Expand Up @@ -136,44 +136,42 @@ fn print_diff_line(formatted_v_code string, expected_v_code string) {
}
}

fn create_json_if_needed(subdir string, test_name string) {
fn create_json(subdir string, test_name string) {
input_file := '${subdir}/${test_name}/${test_name}.go'
output_file := '${input_file}.json'

if !os.exists(output_file) {
// Check if asty is installed
asty_installed := os.system('go list -m -json github.com/asty-org/asty@latest > /dev/null 2>&1') == 0
// Check if asty is installed
asty_installed := os.system('go list -m -json github.com/asty-org/asty@latest > /dev/null 2>&1') == 0

if !asty_installed {
println('asty not found, installing...')
install_result := os.system('go install github.com/asty-org/asty@latest')
if install_result != 0 {
eprintln('Failed to install asty')
return
}
if !asty_installed {
println('asty not found, installing...')
install_result := os.system('go install github.com/asty-org/asty@latest')
if install_result != 0 {
eprintln('Failed to install asty')
return
}
}

println('generating ast for ${input_file}')
println('generating ast for ${input_file}')

run_result := os.system('asty go2json -indent 2 -input ${input_file} -output ${output_file}')
run_result := os.system('asty go2json -indent 2 -input ${input_file} -output ${output_file}')

if run_result != 0 {
eprintln('Failed to run asty')
return
}
if run_result != 0 {
eprintln('Failed to run asty')
return
}

json_content := os.read_file(output_file) or {
eprintln('Failed to read ${output_file}')
return
}
json_content := os.read_file(output_file) or {
eprintln('Failed to read ${output_file}')
return
}

// Replace "NodeType": " with "_type": " to handle sum types
updated_content := json_content.replace('"NodeType": "', '"_type": "')
// Replace "NodeType": " with "_type": " to handle sum types
updated_content := json_content.replace('"NodeType": "', '"_type": "')

os.write_file(output_file, updated_content) or {
eprintln('Failed to write to ${output_file}')
return
}
os.write_file(output_file, updated_content) or {
eprintln('Failed to write to ${output_file}')
return
}
}

Expand All @@ -191,7 +189,7 @@ fn main() {
subdir = os.dir(go_file_name)
test_name := os.base(go_file_name)

create_json_if_needed(subdir, test_name)
create_json(subdir, test_name)

app.run_test(subdir, test_name)!
return
Expand All @@ -201,7 +199,7 @@ fn main() {
test_names.sort()

for test_name in test_names {
create_json_if_needed(subdir, test_name)
create_json(subdir, test_name)

println('===========================================')

Expand Down
277 changes: 0 additions & 277 deletions tests/append/append.go.json

This file was deleted.

Loading

0 comments on commit 94bd142

Please sign in to comment.