main_test.go 647 B

1234567891011121314151617181920212223242526
  1. package main
  2. import "testing"
  3. func TestFormatValueNumericTypeCoercesText(t *testing.T) {
  4. tests := []struct {
  5. name string
  6. value interface{}
  7. colType byte
  8. want string
  9. }{
  10. {"integer text", "123", 'I', "123"},
  11. {"integer nonnumeric text", "ijika", 'I', "0"},
  12. {"real text", "12.345", 'R', "12.3"},
  13. {"real nonnumeric text", "ijika", 'R', "0"},
  14. {"text keeps string", "ijika", 'T', "ijika"},
  15. }
  16. for _, tt := range tests {
  17. t.Run(tt.name, func(t *testing.T) {
  18. if got := formatValue(tt.value, tt.colType); got != tt.want {
  19. t.Fatalf("formatValue(%v, %q) = %q, want %q", tt.value, tt.colType, got, tt.want)
  20. }
  21. })
  22. }
  23. }