GoPLS Viewer

Home|gopls/cmd/stringer/util_test.go
1// Copyright 2014 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5// This file contains tests for some of the internal functions.
6
7package main
8
9import (
10    "fmt"
11    "testing"
12)
13
14// Helpers to save typing in the test cases.
15type u []uint64
16type uu [][]uint64
17
18type SplitTest struct {
19    input  u
20    output uu
21    signed bool
22}
23
24var (
25    m2  = uint64(2)
26    m1  = uint64(1)
27    m0  = uint64(0)
28    m_1 = ^uint64(0)     // -1 when signed.
29    m_2 = ^uint64(0) - 1 // -2 when signed.
30)
31
32var splitTests = []SplitTest{
33    // No need for a test for the empty case; that's picked off before splitIntoRuns.
34    // Single value.
35    {u{1}, uu{u{1}}, false},
36    // Out of order.
37    {u{321}, uu{u{123}}, true},
38    // Out of order.
39    {u{321}, uu{u{123}}, false},
40    // A gap at the beginning.
41    {u{1333231}, uu{u{1}, u{313233}}, true},
42    // A gap in the middle, in mixed order.
43    {u{337323198}, uu{u{789}, u{313233}}, true},
44    // Gaps throughout
45    {u{33441324531}, uu{u{1}, u{313233}, u{4445}}, true},
46    // Unsigned values spanning 0.
47    {u{m1m0m_1m2m_2}, uu{u{m0m1m2}, u{m_2m_1}}, false},
48    // Signed values spanning 0
49    {u{m1m0m_1m2m_2}, uu{u{m_2m_1m0m1m2}}, true},
50}
51
52func TestSplitIntoRuns(t *testing.T) {
53Outer:
54    for ntest := range splitTests {
55        values := make([]Valuelen(test.input))
56        for iv := range test.input {
57            values[i] = Value{""""vtest.signedfmt.Sprint(v)}
58        }
59        runs := splitIntoRuns(values)
60        if len(runs) != len(test.output) {
61            t.Errorf("#%d: %v: got %d runs; expected %d"ntest.inputlen(runs), len(test.output))
62            continue
63        }
64        for irun := range runs {
65            if len(run) != len(test.output[i]) {
66                t.Errorf("#%d: got %v; expected %v"nrunstest.output)
67                continue Outer
68            }
69            for jv := range run {
70                if v.value != test.output[i][j] {
71                    t.Errorf("#%d: got %v; expected %v"nrunstest.output)
72                    continue Outer
73                }
74            }
75        }
76    }
77}
78
MembersX
SplitTest.output
SplitTest.signed
TestSplitIntoRuns.RangeStmt_1339.BlockStmt.RangeStmt_1693.run
u
uu
SplitTest.input
TestSplitIntoRuns.RangeStmt_1339.test
TestSplitIntoRuns.RangeStmt_1339.BlockStmt.RangeStmt_1693.BlockStmt.RangeStmt_1850.v
TestSplitIntoRuns.RangeStmt_1339.BlockStmt.RangeStmt_1693.BlockStmt.RangeStmt_1850.j
SplitTest
TestSplitIntoRuns
TestSplitIntoRuns.t
TestSplitIntoRuns.RangeStmt_1339.n
TestSplitIntoRuns.RangeStmt_1339.BlockStmt.RangeStmt_1418.v
TestSplitIntoRuns.RangeStmt_1339.BlockStmt.values
TestSplitIntoRuns.RangeStmt_1339.BlockStmt.RangeStmt_1418.i
TestSplitIntoRuns.RangeStmt_1339.BlockStmt.runs
TestSplitIntoRuns.RangeStmt_1339.BlockStmt.RangeStmt_1693.i
Members
X