2023-07-20 15:07:10 +02:00
|
|
|
package unittest
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2023-07-24 15:40:14 +02:00
|
|
|
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/decimal"
|
2023-07-20 15:07:10 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestParseInputValue(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
input string
|
|
|
|
exp []sequenceValue
|
|
|
|
failed bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"",
|
|
|
|
nil,
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"testfailed",
|
|
|
|
nil,
|
|
|
|
true,
|
|
|
|
},
|
2023-07-24 15:40:14 +02:00
|
|
|
// stale doesn't support operations
|
|
|
|
{
|
|
|
|
"stalex3",
|
|
|
|
nil,
|
|
|
|
true,
|
|
|
|
},
|
2023-07-20 15:07:10 +02:00
|
|
|
{
|
|
|
|
"-4",
|
|
|
|
[]sequenceValue{{Value: -4}},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"_",
|
|
|
|
[]sequenceValue{{Omitted: true}},
|
|
|
|
false,
|
|
|
|
},
|
2023-07-24 15:40:14 +02:00
|
|
|
{
|
|
|
|
"stale",
|
|
|
|
[]sequenceValue{{Value: decimal.StaleNaN}},
|
|
|
|
false,
|
|
|
|
},
|
2023-07-20 15:07:10 +02:00
|
|
|
{
|
|
|
|
"-4x1",
|
|
|
|
[]sequenceValue{{Value: -4}, {Value: -4}},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"_x1",
|
|
|
|
[]sequenceValue{{Omitted: true}},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"1+1x4",
|
|
|
|
[]sequenceValue{{Value: 1}, {Value: 2}, {Value: 3}, {Value: 4}, {Value: 5}},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"2-1x4",
|
|
|
|
[]sequenceValue{{Value: 2}, {Value: 1}, {Value: 0}, {Value: -1}, {Value: -2}},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
2023-07-24 15:40:14 +02:00
|
|
|
"1+1x1 _ -4 stale 3+20x1",
|
|
|
|
[]sequenceValue{{Value: 1}, {Value: 2}, {Omitted: true}, {Value: -4}, {Value: decimal.StaleNaN}, {Value: 3}, {Value: 23}},
|
2023-07-20 15:07:10 +02:00
|
|
|
false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
output, err := parseInputValue(tc.input, true)
|
|
|
|
if err != nil != tc.failed {
|
|
|
|
t.Fatalf("failed to parse %s, expect %t, got %t", tc.input, tc.failed, err != nil)
|
|
|
|
}
|
2023-07-24 15:40:14 +02:00
|
|
|
if len(tc.exp) != len(output) {
|
2023-07-20 15:07:10 +02:00
|
|
|
t.Fatalf("expect %v, got %v", tc.exp, output)
|
|
|
|
}
|
2023-07-24 15:40:14 +02:00
|
|
|
for i := 0; i < len(tc.exp); i++ {
|
|
|
|
if tc.exp[i].Omitted != output[i].Omitted {
|
|
|
|
t.Fatalf("expect %v, got %v", tc.exp, output)
|
|
|
|
}
|
|
|
|
if tc.exp[i].Value != output[i].Value {
|
|
|
|
if decimal.IsStaleNaN(tc.exp[i].Value) && decimal.IsStaleNaN(output[i].Value) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
t.Fatalf("expect %v, got %v", tc.exp, output)
|
|
|
|
}
|
|
|
|
}
|
2023-07-20 15:07:10 +02:00
|
|
|
}
|
|
|
|
}
|