package pi_test

import "core:os"
import "core:fmt"
import "core:strings"
import "core:testing"

SCRIPT_PATH :: "/Users/einand/Code/test/odin/print_hej"

run_script :: proc(args: []string) -> string {
    cmd: strings.Builder
    strings.init_builder(&cmd)
    defer strings.free_builder(&cmd)
    
    strings.write_string(&cmd, SCRIPT_PATH)
    for arg in args {
        strings.write_byte(&cmd, ' ')
        strings.write_string(&cmd, arg)
    }
    
    process := os.create_process(strings.to_string(cmd))
    defer os.destroy_process(process)
    
    output := os.read_entire_file_from_process(process)
    defer free(output.data)
    
    // Remove trailing newline
    result := string(output.data[:])
    if len(result) > 0 && result[len(result)-1] == '\n' {
        result = result[:len(result)-1]
    }
    
    return result
}

@test "10 decimals"
{
    result := run_script([]string{"10"})
    expected := "3.1415926535"
    testing.expect(result == expected)
}

@test "5 decimals"
{
    result := run_script([]string{"5"})
    expected := "3.14159"
    testing.expect(result == expected)
}

@test "1 decimal"
{
    result := run_script([]string{"1"})
    expected := "3.1"
    testing.expect(result == expected)
}

@test "100 decimals"
{
    result := run_script([]string{"100"})
    expected := "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679"
    testing.expect(result == expected)
}

@test "default 100 decimals"
{
    result := run_script([]string{})
    expected := "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679"
    testing.expect(result == expected)
}

@test "10000 decimals"
{
    result := run_script([]string{"10000"})
    // Check length: "3." + 10000 digits = 10002 characters
    testing.expect(len(result) == 10002)
    testing.expect(strings.has_prefix(result, "3.14159"))
}