Ver código fonte

100% sqllogictest

Danilo Fragoso 4 meses atrás
pai
commit
dcaf8a1412
2 arquivos alterados com 28 adições e 2 exclusões
  1. 2 2
      cmd/sqllogictest/main.go
  2. 26 0
      cmd/sqllogictest/main_test.go

+ 2 - 2
cmd/sqllogictest/main.go

@@ -499,7 +499,7 @@ func formatValue(v interface{}, colType byte) string {
 			if i, err := strconv.ParseInt(n, 10, 64); err == nil {
 				return strconv.FormatInt(i, 10)
 			}
-			return n
+			return "0"
 		default:
 			return fmt.Sprintf("%v", v)
 		}
@@ -515,7 +515,7 @@ func formatValue(v interface{}, colType byte) string {
 			if f, err := strconv.ParseFloat(n, 64); err == nil {
 				return strconv.FormatFloat(f, 'g', 3, 64)
 			}
-			return n
+			return "0"
 		default:
 			return fmt.Sprintf("%v", v)
 		}

+ 26 - 0
cmd/sqllogictest/main_test.go

@@ -0,0 +1,26 @@
+package main
+
+import "testing"
+
+func TestFormatValueNumericTypeCoercesText(t *testing.T) {
+	tests := []struct {
+		name    string
+		value   interface{}
+		colType byte
+		want    string
+	}{
+		{"integer text", "123", 'I', "123"},
+		{"integer nonnumeric text", "ijika", 'I', "0"},
+		{"real text", "12.345", 'R', "12.3"},
+		{"real nonnumeric text", "ijika", 'R', "0"},
+		{"text keeps string", "ijika", 'T', "ijika"},
+	}
+
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			if got := formatValue(tt.value, tt.colType); got != tt.want {
+				t.Fatalf("formatValue(%v, %q) = %q, want %q", tt.value, tt.colType, got, tt.want)
+			}
+		})
+	}
+}