Repository: prometheus/prometheus
File: promql/parser/parse_test.go (Go)

Code before:
				"job", "api-server",
			),
			expectedValues: []SequenceValue{},
		},
		{
			name:  "utf-8 line with value",
			input: `{"http.requests", "service.name"="api-server", instance="0", group="canary"}		0+50x2`,
			expectedLabels: labels.FromStrings(
				"__name__", "http.requests",
				"group", "canary",
				"instance", "0",
				"service.name", "api-server",
			),
			expectedValues: []SequenceValue{
				{Value: 0, Omitted: false, Histogram: (*histogram.FloatHistogram)(nil)},
				{Value: 50, Omitted: false, Histogram: (*histogram.FloatHistogram)(nil)},
				{Value: 100, Omitted: false, Histogram: (*histogram.FloatHistogram)(nil)},
			},
		},
	}

	for _, tc := range tests {
		t.Run(tc.name, func(t *testing.T) {
			l, v, err := ParseSeriesDesc(tc.input)
			require.NoError(t, err)
			require.Zero(t, labels.Compare(tc.expectedLabels, l))
			require.Equal(t, tc.expectedValues, v)
		})
	}
}

// NaN has no equality. Thus, we need a separate test for it.
func TestNaNExpression(t *testing.T) {
	expr, err := ParseExpr("NaN")
	require.NoError(t, err)

	nl, ok := expr.(*NumberLiteral)
	require.True(t, ok, "expected number literal but got %T", expr)
	require.True(t, math.IsNaN(nl.Val), "expected 'NaN' in number literal but got %v", nl.Val)
}

var testSeries = []struct {
	input          string
	expectedMetric labels.Labels
	expectedValues []SequenceValue
	fail           bool
}{
	{
		input:          `{} 1 2 3`,
		expectedMetric: labels.EmptyLabels(),
		expectedValues: newSeq(1, 2, 3),

Review comment (suggestion):
```suggestion
			require.True(t, labels.Equal(tc.expectedLabels, l))
```
We also have `testutil.RequireEqual` which wraps this up.

Code after:
				"instance", "0",
				"job", "api-server",
			),
			expectedValues: []SequenceValue{},
		},
		{
			name:  "label name characters that require quoting",
			input: `{"http.requests", "service.name"="api-server", instance="0", group="canary"}		0+50x2`,
			expectedLabels: labels.FromStrings(
				"__name__", "http.requests",
				"group", "canary",
				"instance", "0",
				"service.name", "api-server",
			),
			expectedValues: []SequenceValue{
				{Value: 0, Omitted: false, Histogram: (*histogram.FloatHistogram)(nil)},
				{Value: 50, Omitted: false, Histogram: (*histogram.FloatHistogram)(nil)},
				{Value: 100, Omitted: false, Histogram: (*histogram.FloatHistogram)(nil)},
			},
		},
		{
			name:        "confirm failure on junk after identifier",
			input:       `{"http.requests"xx}		0+50x2`,
			expectError: `parse error: unexpected identifier "xx" in label set, expected "," or "}"`,
		},
		{
			name:        "confirm failure on bare operator after identifier",
			input:       `{"http.requests"=, x="y"}		0+50x2`,
			expectError: `parse error: unexpected "," in label set, expected string`,
		},
		{
			name:        "confirm failure on unterminated string identifier",
			input:       `{"http.requests}		0+50x2`,
			expectError: `parse error: unterminated quoted string`,
		},
	}

	for _, tc := range tests {
		t.Run(tc.name, func(t *testing.T) {
			l, v, err := ParseSeriesDesc(tc.input)
			if tc.expectError != "" {
				require.Contains(t, err.Error(), tc.expectError)
			} else {
				require.NoError(t, err)
				require.True(t, labels.Equal(tc.expectedLabels, l))
				require.Equal(t, tc.expectedValues, v)
			}
		})
	}
}