Beispiel #1
0
func TestDecoder_errors(t *testing.T) {
	tests := []struct {
		data string
		want error
	}{
		{"a=1\n=bar", &SyntaxError{Msg: "unexpected '='", Line: 2, Pos: 1}},
		{"a=1\n\"k\"=bar", &SyntaxError{Msg: "unexpected '\"'", Line: 2, Pos: 1}},
		{"a=1\nk\"ey=bar", &SyntaxError{Msg: "unexpected '\"'", Line: 2, Pos: 2}},
		{"a=1\nk=b\"ar", &SyntaxError{Msg: "unexpected '\"'", Line: 2, Pos: 4}},
		{"a=1\nk=b =ar", &SyntaxError{Msg: "unexpected '='", Line: 2, Pos: 5}},
		{"a==", &SyntaxError{Msg: "unexpected '='", Line: 1, Pos: 3}},
		{"a=1\nk=b=ar", &SyntaxError{Msg: "unexpected '='", Line: 2, Pos: 4}},
		{"a=\"1", &SyntaxError{Msg: "unterminated quoted value", Line: 1, Pos: 5}},
		{"a=\"1\\", &SyntaxError{Msg: "unterminated quoted value", Line: 1, Pos: 6}},
		{"a=\"\\t1", &SyntaxError{Msg: "unterminated quoted value", Line: 1, Pos: 7}},
		{"a=\"\\u1\"", &SyntaxError{Msg: "invalid quoted value", Line: 1, Pos: 8}},
	}

	for _, test := range tests {
		dec := NewDecoder(strings.NewReader(test.data))

		for dec.ScanRecord() {
			for dec.ScanKeyval() {
			}
		}
		if got, want := dec.Err(), test.want; !reflect.DeepEqual(got, want) {
			t.Errorf("got: %v, want: %v", got, want)
		}
	}
}
Beispiel #2
0
func TestGlobPatternPrefix(t *testing.T) {
	var globberTests = []struct {
		glob   string
		prefix string
	}{
		{"foo.bar", "foo.bar"},

		{"foo.*.*.bar", "foo."},
		{"foo?", "foo"},
		{"foo]bar", "foo"},
		{"foo[bar", "foo"},

		{"trailing\\", "trailing\\"},
		{"escaped.\\*.star", "escaped.\\*.star"},
	}

	for _, tt := range globberTests {
		// Build a query
		out := GlobPatternPrefix(tt.glob)

		if out != tt.prefix {
			t.Errorf("Expected '%v' to have prefix '%v', got '%v'.", tt.glob, tt.prefix, out)
		}
	}
}
Beispiel #3
0
func TestSplit(t *testing.T) {
	s := split("a,b,", ',')
	if len(s) != 3 || "a" != s[0] || "b" != s[1] || "" != s[2] {
		t.Errorf("%v\n", s)
	}

	s = split(",", ',')
	if len(s) != 2 || "" != s[0] || "" != s[1] {
		t.Errorf("%v\n", s)
	}

	s = split("", ',')
	if len(s) != 1 || s[0] != "" {
		t.Errorf("%v\n", s)
	}

	s = split("a", ',')
	if len(s) != 1 || s[0] != "a" {
		t.Errorf("%v\n", s)
	}

	s = split("a\\\\,b,:,", ',')
	if len(s) != 4 || "a\\\\" != s[0] || "b" != s[1] || ":" != s[2] || "" != s[3] {
		t.Errorf("%v\n", s)
	}
func TestExportControl(t *testing.T) {
	for _, example := range exportControlTests {
		dir, err := ioutil.TempDir("", "example")
		if err != nil {
			log.Fatal(err)
		}
		defer os.RemoveAll(dir)
		openControlData, errs := models.LoadData(example.opencontrolDir, example.certificationPath)
		if len(errs) > 0 {
			log.Fatal("Should have loaded the opencontrol data.")
		}
		openControl := OpenControlGitBook{
			openControlData,
			"",
			dir,
			fs.OSUtil{},
		}
		control := openControl.Standards.Get(example.standardKey).Controls[example.controlKey]
		actualPath, actualText := openControl.exportControl(&ControlGitbook{&control, dir, example.standardKey, example.controlKey})
		expectedPath := filepath.Join(dir, example.expectedPath)
		// Verify the expected export path is the same as the actual export path
		if expectedPath != actualPath {
			t.Errorf("Expected %s, Actual: %s", example.expectedPath, actualPath)
		}
		// Verify the expected text is the same as the actual text
		if example.expectedText != strings.Replace(actualText, "\\", "/", -1) {
			t.Errorf("Expected %s, Actual: %s", example.expectedText, actualText)
		}

	}
Beispiel #5
0
func Test_vm01(tst *testing.T) {

	//verbose()
	chk.PrintTitle("vm01")

	// allocate driver
	ndim, pstress := 2, false
	simfnk, modelname := "test", "vm"
	var drv Driver
	err := drv.Init(simfnk, modelname, ndim, pstress, []*fun.Prm{
		&fun.Prm{N: "K", V: 1.5},
		&fun.Prm{N: "G", V: 1},
		&fun.Prm{N: "qy0", V: 2},
		&fun.Prm{N: "H", V: 0.5},
	})
	drv.CheckD = true
	if err != nil {
		tst.Errorf("test failed: %v\n", err)
		return
	}

	// vm model
	vm := drv.model.(*VonMises)

	// path
	p0 := 0.0
	Δp := 3.0
	Δq := vm.qy0
	ϵ := 1e-3
	DP := []float64{Δp + ϵ, 3, 2, 1, 0}
func TestBuildGitbook(t *testing.T) {
	for _, example := range buildGitbookTests {
		tempDir, _ := ioutil.TempDir("", "example")
		defer os.RemoveAll(tempDir)
		config := Config{
			OpencontrolDir: example.inputDir,
			Certification:  example.certificationPath,
			ExportPath:     tempDir,
			MarkdownPath:   example.markdownPath,
		}

		config.BuildGitbook()
		// Loop through the expected output to verify it matches the actual output
		matches, _ := filepath.Glob(filepath.Join(example.expectedOutputDir, "*", "*"))
		for _, expectedfilePath := range matches {
			actualFilePath := strings.Replace(expectedfilePath, example.expectedOutputDir, tempDir, -1)
			expectedData, _ := ioutil.ReadFile(expectedfilePath)
			actualData, _ := ioutil.ReadFile(actualFilePath)
			actualDataString := strings.Replace(string(actualData), "\\", "/", -1)
			// Verify the expected text is the same as the actual text
			if string(expectedData) != actualDataString {
				t.Errorf("Expected (%s):\n`%s`\nActual:\n`%s`", expectedfilePath, string(expectedData), string(actualData))
			}
		}
	}
}
func TestBaseDirectory(t *testing.T) {
	mustStr := "Hello from template_tests/base_dir_test/"

	fs := pongo2.MustNewLocalFileSystemLoader("")
	s := pongo2.NewSet("test set with base directory", fs)
	s.Globals["base_directory"] = "template_tests/base_dir_test/"
	if err := fs.SetBaseDir(s.Globals["base_directory"].(string)); err != nil {
		t.Fatal(err)
	}

	matches, err := filepath.Glob("./template_tests/base_dir_test/subdir/*")
	if err != nil {
		t.Fatal(err)
	}
	for _, match := range matches {
		if "windows" == runtime.GOOS {
			match = strings.Replace(match, "template_tests\\base_dir_test\\", "", -1)
		} else {
			match = strings.Replace(match, "template_tests/base_dir_test/", "", -1)
		}

		tpl, err := s.FromFile(match)
		if err != nil {
			t.Fatal(err)
		}
		out, err := tpl.Execute(nil)
		if err != nil {
			t.Fatal(err)
		}
		if out != mustStr {
			t.Errorf("%s: out ('%s') != mustStr ('%s')", match, out, mustStr)
		}
	}
}
func TestEmitLabelSet(t *testing.T) {
	v := NewMetric("test", "prog", Gauge, "foo", "bar", "quux")
	c := make(chan *LabelSet)

	quit := make(chan bool)
	ts := time.Now()

	for _, tc := range labelSetTests {
		d, _ := v.GetDatum(tc.values...)
		d.Set(37, ts)
	}
	go v.EmitLabelSets(c, quit)
	expected_datum := &Datum{37, ts}
	for _, tc := range labelSetTests {
		select {
		case l := <-c:
			if !reflect.DeepEqual(expected_datum, l.datum) {
				t.Errorf("Datum no match: expected %v, received %v\n", expected_datum, l.datum)
			}
			if !reflect.DeepEqual(tc.expected_labels, l.labels) {
				t.Errorf("Labels don't match: expected %v, received %v\n", tc.expected_labels, l.labels)
			}
		case <-quit:
			goto out
		}
	}
out:
}
Beispiel #9
0
func TestParseLinkDestination(t *testing.T) {
	type testCase struct {
		in     string
		title  string
		endpos int
		ok     bool
	}
	testCases := []testCase{
		{"<\\>>", ">", 4, true},
		{"http://goo gle.com", "http://goo", 10, true},
		{"http://google.com", "http://google.com", 17, true},
		{"http://google.com/search?query=(1)", "http://google.com/search?query=(1)", 34, true},
		{"http://google.com/search?query=)1(", "http://google.com/search?query=", 31, true},
		{"http://google.com/search?query=((1))", "http://google.com/search?query=(", 32, true},
		{`http://google.com/search?query=a\ b\ c`, `http://google.com/search?query=a\ b\ c`, 38, true},
		{"http://goo\x00gle.com", "http://goo", 10, true},
		{"<link>", "link", 6, true},
		{"<", "", 0, false},
		{"<\\>", "", 0, false},
		{"<\\", "", 0, false},
		{"", "", 0, false},
		{"<>", "", 2, true},
		{"<link", "", 0, false},
		{"<\n", "", 0, false},
	}
	for _, tc := range testCases {
		title, endpos, ok := parseLinkDestination(tc.in, 0, len(tc.in))
		if title != tc.title || endpos != tc.endpos || ok != tc.ok {
			t.Errorf("parseLinkDestination(%q) = (%q, %d, %v), want (%q, %d, %v)", tc.in, title, endpos, ok, tc.title, tc.endpos, tc.ok)
		}
	}
}
Beispiel #10
0
// Test key expansion against FIPS 197 examples.
func TestExpandKey(t *testing.T) {
L:
	for i, tt := range keyTests {
		enc := make([]uint32, len(tt.enc))
		var dec []uint32
		if tt.dec != nil {
			dec = make([]uint32, len(tt.dec))
		}
		// This test could only test Go version of expandKey because asm
		// version might use different memory layout for expanded keys
		// This is OK because we don't expose expanded keys to the outside
		expandKeyGo(tt.key, enc, dec)
		for j, v := range enc {
			if v != tt.enc[j] {
				t.Errorf("key %d: enc[%d] = %#x, want %#x", i, j, v, tt.enc[j])
				continue L
			}
		}
		if dec != nil {
			for j, v := range dec {
				if v != tt.dec[j] {
					t.Errorf("key %d: dec[%d] = %#x, want %#x", i, j, v, tt.dec[j])
					continue L
				}
			}
		}
	}
}
Beispiel #11
0
func Test_dp01(tst *testing.T) {

	//verbose()
	chk.PrintTitle("dp01")

	// allocate driver
	ndim, pstress := 2, false
	simfnk, modelname := "test", "dp"
	var drv Driver
	err := drv.Init(simfnk, modelname, ndim, pstress, []*fun.Prm{
		&fun.Prm{N: "K", V: 1.5},
		&fun.Prm{N: "G", V: 1},
		&fun.Prm{N: "M", V: 0},
		&fun.Prm{N: "Mb", V: 0},
		&fun.Prm{N: "qy0", V: 2},
		&fun.Prm{N: "H", V: 0.5},
	})
	drv.CheckD = true
	drv.VerD = false // verbose
	if err != nil {
		tst.Errorf("test failed: %v\n", err)
		return
	}

	// dp model
	dp := drv.model.(*DruckerPrager)

	// path
	p0 := 0.0
	Δp := 3.0
	Δq := dp.qy0 + dp.M*Δp
	ϵ := 1e-3
	DP := []float64{Δp + ϵ, 3, 2, 1, 0}
Beispiel #12
0
func TestToTomlValue(t *testing.T) {
	for idx, item := range []struct {
		Value  interface{}
		Expect string
	}{
		{int(1), "1"},
		{int8(2), "2"},
		{int16(3), "3"},
		{int32(4), "4"},
		{int64(12345), "12345"},
		{uint(10), "10"},
		{uint8(20), "20"},
		{uint16(30), "30"},
		{uint32(40), "40"},
		{uint64(50), "50"},
		{float32(12.456), "12.456"},
		{float64(123.45), "123.45"},
		{bool(true), "true"},
		{"hello world", "\"hello world\""},
		{"\b\t\n\f\r\"\\", "\"\\b\\t\\n\\f\\r\\\"\\\\\""},
		{"\x05", "\"\\u0005\""},
		{time.Date(1979, time.May, 27, 7, 32, 0, 0, time.UTC),
			"1979-05-27T07:32:00Z"},
		{[]interface{}{"gamma", "delta"},
			"[\n  \"gamma\",\n  \"delta\",\n]"},
		{nil, ""},
	} {
		result := toTomlValue(item.Value, 0)
		if result != item.Expect {
			t.Errorf("Test %d - got '%s', expected '%s'", idx, result, item.Expect)
		}
	}
}
Beispiel #13
0
func TestStringMatchBackSlash(t *testing.T) {
	pat, str := "\\*\\?\\[\\]\\\\", "*?[]\\"

	if !StringMatch(pat, str) {
		t.Errorf("StringMatch should have matched pattern %q with string %q", pat, str)
	}
}
Beispiel #14
0
func TestExtractRx(t *testing.T) {
	tests := []struct {
		in, out string
	}{
		{"", ""},
		{"/foo", ""},
		{"foo", "foo"},
		{"foo/bar", "foo"},
		{"foo\\/bar", "foo\\/bar"},
		{"foo\\/bar/", "foo\\/bar"},
		{"foo\\\\/bar", "foo\\\\"},
		{"foo\\\\\\/bar", "foo\\\\\\/bar"},
		{"foo\\", "foo\\"},
		{"foo\\\\", "foo\\\\"},
		{"\\/", "\\/"},
		{"\\//", "\\/"},
		{"\\\\/", "\\\\"},
		{"\\\\//", "\\\\"},
		{"\\/foo", "\\/foo"},
	}
	for i, test := range tests {
		l := &util.Lexer{Input: test.in}
		if o := extractRx(l, '/'); o != test.out {
			t.Errorf("extractRx(%d) '%s': exp '%s' got '%s'",
				i, test.in, test.out, o)
		}
	}
}
Beispiel #15
0
func TestLex(t *testing.T) {
	for i, tt := range lexTests {
		ret := lexcollect(lex("test", tt.input))
		if !reflect.DeepEqual(ret, tt.expected) {
			t.Errorf("%d %q - expected\n%v\ngot\n%v", i, tt.input, tt.expected, ret)
		}
	}
}
Beispiel #16
0
func TestValidateLocal(t *testing.T) {
	var testTable = []struct {
		input  string
		expect bool
		msg    string
	}{
		{"", false, "Empty local is not valid"},
		{"a", true, "Single letter should be fine"},
		{strings.Repeat("a", 65), false, "Only valid up to 64 characters"},
		{"FirstLast", true, "Mixed case permitted"},
		{"user123", true, "Numbers permitted"},
		{"a!#$%&'*+-/=?^_`{|}~", true, "Any of !#$%&'*+-/=?^_`{|}~ are permitted"},
		{"first.last", true, "Embedded period is permitted"},
		{"first..last", false, "Sequence of periods is not allowed"},
		{".user", false, "Cannot lead with a period"},
		{"user.", false, "Cannot end with a period"},
		{"james@mail", false, "Unquoted @ not permitted"},
		{"first last", false, "Unquoted space not permitted"},
		{"tricky\\. ", false, "Unquoted space not permitted"},
		{"no,commas", false, "Unquoted comma not allowed"},
		{"t[es]t", false, "Unquoted square brackets not allowed"},
		{"james\\", false, "Cannot end with backslash quote"},
		{"james\\@mail", true, "Quoted @ permitted"},
		{"quoted\\ space", true, "Quoted space permitted"},
		{"no\\,commas", true, "Quoted comma is OK"},
		{"t\\[es\\]t", true, "Quoted brackets are OK"},
		{"user\\name", true, "Should be able to quote a-z"},
		{"USER\\NAME", true, "Should be able to quote A-Z"},
		{"user\\1", true, "Should be able to quote a digit"},
		{"one\\$\\|", true, "Should be able to quote plain specials"},
		{"return\\\r", true, "Should be able to quote ASCII control chars"},
		{"high\\\x80", false, "Should not accept > 7-bit quoted chars"},
		{"quote\\\"", true, "Quoted double quote is permitted"},
		{"\"james\"", true, "Quoted a-z is permitted"},
		{"\"first last\"", true, "Quoted space is permitted"},
		{"\"quoted@sign\"", true, "Quoted @ is allowed"},
		{"\"qp\\\"quote\"", true, "Quoted quote within quoted string is OK"},
		{"\"unterminated", false, "Quoted string must be terminated"},
		{"\"unterminated\\\"", false, "Quoted string must be terminated"},
		{"embed\"quote\"string", false, "Embedded quoted string is illegal"},

		{"user+mailbox", true, "RFC3696 test case should be valid"},
		{"customer/department=shipping", true, "RFC3696 test case should be valid"},
		{"$A12345", true, "RFC3696 test case should be valid"},
		{"!def!xyz%abc", true, "RFC3696 test case should be valid"},
		{"_somename", true, "RFC3696 test case should be valid"},
	}

	for _, tt := range testTable {
		_, _, err := ParseEmailAddress(tt.input + "@domain.com")
		if (err != nil) == tt.expect {
			if err != nil {
				t.Logf("Got error: %s", err)
			}
			t.Errorf("Expected %v for %q: %s", tt.expect, tt.input, tt.msg)
		}
	}
}
Beispiel #17
0
func TestAddBackSlash(t *testing.T) {
	// バックスラッシュ必要
	if dir := AddBackSlash("sample"); dir != "sample\\" {
		t.Errorf("バックスラッシュ必要時の動作不正 [%s]", dir)
	}

	// バックスラッシュ不要
	if dir := AddBackSlash("sample\\"); dir != "sample\\" {
		t.Errorf("バックスラッシュ不要時の動作不正 [%s]", dir)
	}
}
Beispiel #18
0
func TestNewHeaders(t *testing.T) {
	for _, test := range newHeadersTests {
		h := NewHeaders(test.list)
		expect := test.headers
		actual := h.headers
		if !reflect.DeepEqual(actual, expect) {
			t.Errorf("NewHeaders(%q).headers:\ngot :%q\nwant:%q",
				test.list, actual, expect)
		}
	}
}
Beispiel #19
0
// Verify that our isPrint agrees with unicode.IsPrint
func TestIsPrint(t *testing.T) {
	n := 0
	for r := rune(0); r <= unicode.MaxRune; r++ {
		if IsPrint(r) != unicode.IsPrint(r) {
			t.Errorf("IsPrint(%U)=%t incorrect", r, IsPrint(r))
			n++
			if n > 10 {
				return
			}
		}
	}
}
Beispiel #20
0
func TestSplit(t *testing.T) {
	want := []string{"one", "two", "three four", "five \"six\"", "seven#eight", "eleven", "twelve\\", "thirteen=13", "fourteen/14"}
	got, err := Split(testString)
	if err != nil {
		t.Error(err)
	}
	if len(want) != len(got) {
		t.Errorf("Split(%q) -> %v. Want: %v", testString, got, want)
	}
	for i := range got {
		if got[i] != want[i] {
			t.Errorf("Split(%q)[%v] -> %v. Want: %v", testString, i, got[i], want[i])
		}
	}
}
Beispiel #21
0
func TestLexer(t *testing.T) {
	testInput := strings.NewReader(testString)
	expectedStrings := []string{"one", "two", "three four", "five \"six\"", "seven#eight", "eleven", "twelve\\", "thirteen=13", "fourteen/14"}

	lexer := NewLexer(testInput)
	for i, want := range expectedStrings {
		got, err := lexer.Next()
		if err != nil {
			t.Error(err)
		}
		if got != want {
			t.Errorf("Lexer.Next()[%v] of %q -> %v. Want: %v", i, testString, got, want)
		}
	}
}
Beispiel #22
0
func TestBruteAttack(t *testing.T) {
	const (
		charset = "abcdefghijklmnopqrstuvwxyz"
	)

	message, err := ioutil.ReadFile(os.Getenv("GOPATH") + "src/github.com/karlek/tombraid/message.txt")

	csLen := len(charset)
	for i := 0; i < csLen; i++ {

	message, err := BruteAttack(charset, cipher)
	if err != nil {
		t.Errorf("BruteAttack(%v, %v) - failed with error: %s\n", charset, cipher, err.Error())
	}
}
// Test getPath() - the path that needs to be passed to newPosix()
func TestGetPath(t *testing.T) {
	globalMinioHost = ""
	var testCases []struct {
		epStr string
		path  string
	}
	if runtime.GOOS == "windows" {
		testCases = []struct {
			epStr string
			path  string
		}{
			{"\\export", "\\export"},
			{"D:\\export", "d:\\export"},
			{"D:\\", "d:\\"},
			{"D:", "d:"},
			{"\\", "\\"},
			{"http://localhost/d:/export", "d:/export"},
			{"https://localhost/d:/export", "d:/export"},
		}
	} else {
		testCases = []struct {
			epStr string
			path  string
		}{
			{"/export", "/export"},
			{"http://localhost/export", "/export"},
			{"https://localhost/export", "/export"},
		}
	}
	testCasesCommon := []struct {
		epStr string
		path  string
	}{
		{"export", "export"},
	}
	testCases = append(testCases, testCasesCommon...)
	for i, test := range testCases {
		eps, err := parseStorageEndpoints([]string{test.epStr})
		if err != nil {
			t.Errorf("Test %d: %s - %s", i+1, test.epStr, err)
			continue
		}
		path := getPath(eps[0])
		if path != test.path {
			t.Errorf("Test %d: For endpoing %s, getPath() failed, got: %s, expected: %s,", i+1, test.epStr, path, test.path)
		}
	}
}
Beispiel #24
0
func TestEncodeSQLBytes(t *testing.T) {
	testCases := []struct {
		arg      string
		expected string
	}{
		{"", "X''"},
		{"abcd", "X'61626364'"},
		{"\x00'\"\b\n\r\t\x1A\\", "X'002722080a0d091a5c'"},
	}
	for _, c := range testCases {
		encoded := encodeSQLBytes(nil, []byte(c.arg))
		if string(encoded) != c.expected {
			t.Errorf("Expected %s, but got %s", c.expected, encoded)
		}
	}
}
Beispiel #25
0
func TestNewURI(t *testing.T) {
	tests := []struct{ in, want string }{
		{"", ""},
		{"<>\"{}|^`\\", ""},
		{"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F", ""},
		{"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20", ""},
		{"æøå", "æøå"},
		{" http://example.org/resorce#123 ", "http://example.org/resorce#123"},
	}

	for _, test := range tests {
		if NewURI(test.in).String() != test.want {
			t.Errorf("NewURI(%q) => %q; want %q", test.in, NewURI(test.in), test.want)
		}
	}
}
Beispiel #26
0
func TestPlatformAbsPathify(t *testing.T) {
	type test struct {
		inPath, workingDir, expected string
	}
	data := []test{
		{"c:\\banana\\..\\dir", "c:\\foo", "c:\\dir"},
		{"\\dir", "c:\\foo", "c:\\foo\\dir"},
		{"c:\\", "c:\\foo", "c:\\"},
	}

	for i, d := range data {
		// todo see comment in AbsPathify
		viper.Set("WorkingDir", d.workingDir)

		expected := AbsPathify(d.inPath)
		if d.expected != expected {
			t.Errorf("Test %d failed. Expected %q but got %q", i, d.expected, expected)
		}
	}
}
func TestBuildComponentsSummaries(t *testing.T) {
	for _, example := range buildComponentsSummariesTests {
		openControlData, _ := lib.LoadData(example.opencontrolDir, example.certificationPath)
		openControl := OpenControlGitBook{
			openControlData,
			"",
			example.exportPath,
			fs.OSUtil{},
		}
		actualSummary := openControl.buildComponentsSummaries()
		data, err := ioutil.ReadFile(example.expectedSummary)
		if err != nil {
			log.Fatal(err)
		}
		expectedSummary := string(data)
		// Check that the actual and expected summaries are similar
		if strings.Replace(actualSummary, "\\", "/", -1) != expectedSummary {
			t.Errorf("Expected: `%s`, Actual: `%s`", expectedSummary, actualSummary)
		}
	}
Beispiel #28
0
func TestEncode(t *testing.T) {
	type testCase struct {
		in   string
		want string
	}
	testCases := []testCase{
		{"", ""},
		{";/?:@&=+$,-_.!~*'()#012azAZ", ";/?:@&=+$,-_.!~*'()#012azAZ"},
		{" `%^{}\"<>\\", "%20%60%25%5E%7B%7D%22%3C%3E%5C"},
		{"%7e%25%7E", "%7E%25%7E"},
		{"%1g%z2%", "%251g%25z2%25"},
		{"процесс", "%D0%BF%D1%80%D0%BE%D1%86%D0%B5%D1%81%D1%81"},
	}
	for _, tc := range testCases {
		got := Encode(tc.in)
		if got != tc.want {
			t.Errorf("Encode(%q) = %q, want %q", tc.in, got, tc.want)
		}
	}
}
Beispiel #29
0
func TestEncodeSQLString(t *testing.T) {
	testCases := []struct {
		arg      string
		expected string
	}{
		{"abcd", "'abcd'"},
		{"workin' hard", "'workin\\' hard'"},
		{"\x00'\"\b\n\r\t\x1A\\", `'\0\'\"\b\n\r\t\Z\\'`},
		// Three different representations of the same unicode string.
		{"\xE7\xB1\xB3\xE6\xB4\xBE", "'米派'"},
		{"\u7C73\u6D3E", "'米派'"},
		{"米派", "'米派'"},
	}
	for _, c := range testCases {
		encoded := encodeSQLString(nil, []byte(c.arg))
		if string(encoded) != c.expected {
			t.Errorf("Expected %s, but got %s", c.expected, encoded)
		}
	}
}
Beispiel #30
0
func assertEquals(descr string, want, have interface{}, t *testing.T) {
	ok := false
	switch want := want.(type) {
	case int:
		ok = want == have.(int)

	case string:
		ok = want == have.(string)

	case Diffs:
		have := have.(Diffs)
		if len(want) == len(have) {
			for i := range want {
				if have[i] != want[i] {
					goto sorry
				}
			}
			ok = true
		sorry:
		}

	case *linesDesc:
		have := have.(*linesDesc)
	s:
		switch {
		case have.chars1 != want.chars1:
		case have.chars2 != want.chars2:
		case len(have.lines) != len(have.lines):
		default:
			for i := range have.lines {
				if have.lines[i] != want.lines[i] {
					break s
				}
			}
			ok = true
		}
	}
	if !ok {
		t.Errorf("%s.\n\twant: %v\n\thave: %v\n", descr, want, have)
	}
}