Skip to content

Commit

Permalink
tidied and simplified test package
Browse files Browse the repository at this point in the history
  • Loading branch information
JetSetIlly committed Jul 6, 2023
1 parent 1b021cc commit 732c433
Show file tree
Hide file tree
Showing 25 changed files with 225 additions and 721 deletions.
52 changes: 26 additions & 26 deletions coprocessor/developer/leb128/leb128_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,69 +26,69 @@ func TestDecodeULEB128(t *testing.T) {
// tests from page 162 of the "DWARF4 Standard"
v := []uint8{0x7f, 0x00}
r, n := leb128.DecodeULEB128(v)
test.Equate(t, n, 1)
test.Equate(t, r, uint64(127))
test.ExpectEquality(t, n, 1)
test.ExpectEquality(t, r, uint64(127))

v = []uint8{0x80, 0x01, 0x00}
r, n = leb128.DecodeULEB128(v)
test.Equate(t, n, 2)
test.Equate(t, r, uint64(128))
test.ExpectEquality(t, n, 2)
test.ExpectEquality(t, r, uint64(128))

v = []uint8{0x81, 0x01, 0x00}
r, n = leb128.DecodeULEB128(v)
test.Equate(t, n, 2)
test.Equate(t, r, uint64(129))
test.ExpectEquality(t, n, 2)
test.ExpectEquality(t, r, uint64(129))

v = []uint8{0x82, 0x01, 0x00}
r, n = leb128.DecodeULEB128(v)
test.Equate(t, n, 2)
test.Equate(t, r, uint64(130))
test.ExpectEquality(t, n, 2)
test.ExpectEquality(t, r, uint64(130))

v = []uint8{0xb9, 0x64, 0x00}
r, n = leb128.DecodeULEB128(v)
test.Equate(t, n, 2)
test.Equate(t, r, uint64(12857))
test.ExpectEquality(t, n, 2)
test.ExpectEquality(t, r, uint64(12857))
}

func TestDecodeSLEB128(t *testing.T) {
// tests from page 163 of the "DWARF4 Standard"
v := []uint8{0x02, 0x00}
r, n := leb128.DecodeSLEB128(v)
test.Equate(t, n, 1)
test.Equate(t, r, int64(2))
test.ExpectEquality(t, n, 1)
test.ExpectEquality(t, r, int64(2))

v = []uint8{0x7e, 0x00}
r, n = leb128.DecodeSLEB128(v)
test.Equate(t, n, 1)
test.Equate(t, r, int64(-2))
test.ExpectEquality(t, n, 1)
test.ExpectEquality(t, r, int64(-2))

v = []uint8{0xff, 0x00}
r, n = leb128.DecodeSLEB128(v)
test.Equate(t, n, 2)
test.Equate(t, r, int64(127))
test.ExpectEquality(t, n, 2)
test.ExpectEquality(t, r, int64(127))

v = []uint8{0x81, 0x7f}
r, n = leb128.DecodeSLEB128(v)
test.Equate(t, n, 2)
test.Equate(t, r, int64(-127))
test.ExpectEquality(t, n, 2)
test.ExpectEquality(t, r, int64(-127))

v = []uint8{0x80, 0x01}
r, n = leb128.DecodeSLEB128(v)
test.Equate(t, n, 2)
test.Equate(t, r, int64(128))
test.ExpectEquality(t, n, 2)
test.ExpectEquality(t, r, int64(128))

v = []uint8{0x80, 0x7f}
r, n = leb128.DecodeSLEB128(v)
test.Equate(t, n, 2)
test.Equate(t, r, int64(-128))
test.ExpectEquality(t, n, 2)
test.ExpectEquality(t, r, int64(-128))

v = []uint8{0x81, 0x01}
r, n = leb128.DecodeSLEB128(v)
test.Equate(t, n, 2)
test.Equate(t, r, int64(129))
test.ExpectEquality(t, n, 2)
test.ExpectEquality(t, r, int64(129))

v = []uint8{0xff, 0x7e}
r, n = leb128.DecodeSLEB128(v)
test.Equate(t, n, 2)
test.Equate(t, r, int64(-129))
test.ExpectEquality(t, n, 2)
test.ExpectEquality(t, r, int64(-129))
}
58 changes: 29 additions & 29 deletions debugger/terminal/commandline/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func expectEquivalency(t *testing.T, cmds *commandline.Commands) {

template := strings.Split(cmds.String(), "\n")
cmds, err = commandline.ParseCommandTemplate(template)
if test.ExpectedSuccess(t, err) {
if test.ExpectSuccess(t, err) {
expectEquality(t, template, cmds)
}
}
Expand All @@ -73,14 +73,14 @@ func TestParser_optimised(t *testing.T) {
template = []string{"TEST [1 [2] [3] [4] [5]]"}

cmds, err = commandline.ParseCommandTemplate(template)
if test.ExpectedSuccess(t, err) {
if test.ExpectSuccess(t, err) {
expectEquivalency(t, cmds)
}

template = []string{"TEST (egg|fog|(nug nog)|big) (tug)"}

cmds, err = commandline.ParseCommandTemplate(template)
if test.ExpectedSuccess(t, err) {
if test.ExpectSuccess(t, err) {
expectEquivalency(t, cmds)
}
}
Expand All @@ -93,7 +93,7 @@ func TestParser_nestedGroups(t *testing.T) {
template = []string{"TEST (foo|bar (a|b c|d) baz)"}

cmds, err = commandline.ParseCommandTemplate(template)
if test.ExpectedSuccess(t, err) {
if test.ExpectSuccess(t, err) {
expectEquality(t, template, cmds)
}
}
Expand All @@ -103,11 +103,11 @@ func TestParser_badGroupings(t *testing.T) {

// optional groups must be closed
_, err = commandline.ParseCommandTemplate([]string{"TEST (arg"})
test.ExpectedFailure(t, err)
test.ExpectFailure(t, err)

// required groups must be closed
_, err = commandline.ParseCommandTemplate([]string{"TEST (arg]"})
test.ExpectedFailure(t, err)
test.ExpectFailure(t, err)
}

func TestParser_goodGroupings(t *testing.T) {
Expand All @@ -118,7 +118,7 @@ func TestParser_goodGroupings(t *testing.T) {
template = []string{"TEST (1 [2] [3] [4] [5])"}

cmds, err = commandline.ParseCommandTemplate(template)
if test.ExpectedSuccess(t, err) {
if test.ExpectSuccess(t, err) {
expectEquality(t, template, cmds)
}
}
Expand All @@ -131,21 +131,21 @@ func TestParser_nestedGroupings(t *testing.T) {
template = []string{"TEST [(foo)|bar]"}

cmds, err = commandline.ParseCommandTemplate(template)
if test.ExpectedSuccess(t, err) {
if test.ExpectSuccess(t, err) {
expectEquality(t, template, cmds)
}

template = []string{"TEST (foo|[bar])"}

cmds, err = commandline.ParseCommandTemplate(template)
if test.ExpectedSuccess(t, err) {
if test.ExpectSuccess(t, err) {
expectEquality(t, template, cmds)
}

template = []string{"TEST (foo|[bar|(baz|qux)]|wibble)"}

cmds, err = commandline.ParseCommandTemplate(template)
if test.ExpectedSuccess(t, err) {
if test.ExpectSuccess(t, err) {
expectEquality(t, template, cmds)
}
}
Expand All @@ -158,7 +158,7 @@ func TestParser_rootGroupings(t *testing.T) {
template = []string{"TEST (arg)"}

cmds, err = commandline.ParseCommandTemplate(template)
if test.ExpectedSuccess(t, err) {
if test.ExpectSuccess(t, err) {
expectEquality(t, template, cmds)
}
}
Expand All @@ -170,22 +170,22 @@ func TestParser_placeholders(t *testing.T) {

// placeholder directives must be complete
_, err = commandline.ParseCommandTemplate([]string{"TEST foo %"})
test.ExpectedFailure(t, err)
test.ExpectFailure(t, err)

// placeholder directives must be recognised
_, err = commandline.ParseCommandTemplate([]string{"TEST foo %q"})
test.ExpectedFailure(t, err)
test.ExpectFailure(t, err)

// double %% is a valid placeholder directive
template = []string{"TEST foo %%"}
cmds, err = commandline.ParseCommandTemplate(template)
if test.ExpectedSuccess(t, err) {
if test.ExpectSuccess(t, err) {
expectEquality(t, template, cmds)
}

// placeholder directives must be separated from surrounding text
_, err = commandline.ParseCommandTemplate([]string{"TEST foo%%"})
test.ExpectedFailure(t, err)
test.ExpectFailure(t, err)
}

func TestParser_doubleArgs(t *testing.T) {
Expand All @@ -196,21 +196,21 @@ func TestParser_doubleArgs(t *testing.T) {
template = []string{"TEST foo bar"}

cmds, err = commandline.ParseCommandTemplate(template)
if test.ExpectedSuccess(t, err) {
if test.ExpectSuccess(t, err) {
expectEquality(t, template, cmds)
}

template = []string{"TEST (foo bar baz)"}

cmds, err = commandline.ParseCommandTemplate(template)
if test.ExpectedSuccess(t, err) {
if test.ExpectSuccess(t, err) {
expectEquality(t, template, cmds)
}

template = []string{"TEST (egg|fog|nug nog|big) (tug)"}

cmds, err = commandline.ParseCommandTemplate(template)
if test.ExpectedSuccess(t, err) {
if test.ExpectSuccess(t, err) {
expectEquality(t, template, cmds)
}
}
Expand All @@ -223,42 +223,42 @@ func TestParser_repeatGroups(t *testing.T) {
template = []string{"TEST {foo}"}

cmds, err = commandline.ParseCommandTemplate(template)
if test.ExpectedSuccess(t, err) {
if test.ExpectSuccess(t, err) {
expectEquality(t, template, cmds)
}

template = []string{"TEST {foo|bar}"}

cmds, err = commandline.ParseCommandTemplate(template)
if test.ExpectedSuccess(t, err) {
if test.ExpectSuccess(t, err) {
expectEquality(t, template, cmds)
}

template = []string{"TEST {[foo|bar]}"}

cmds, err = commandline.ParseCommandTemplate(template)
if test.ExpectedSuccess(t, err) {
if test.ExpectSuccess(t, err) {
expectEquality(t, template, cmds)
}

template = []string{"TEST {foo|bar|baz}"}

cmds, err = commandline.ParseCommandTemplate(template)
if test.ExpectedSuccess(t, err) {
if test.ExpectSuccess(t, err) {
expectEquality(t, template, cmds)
}

template = []string{"TEST {foo %f}"}

cmds, err = commandline.ParseCommandTemplate(template)
if test.ExpectedSuccess(t, err) {
if test.ExpectSuccess(t, err) {
expectEquality(t, template, cmds)
}

template = []string{"TEST {foo|bar %f}"}

cmds, err = commandline.ParseCommandTemplate(template)
if test.ExpectedSuccess(t, err) {
if test.ExpectSuccess(t, err) {
expectEquality(t, template, cmds)
}
}
Expand All @@ -277,16 +277,16 @@ func TestParser_addHelp(t *testing.T) {
}

cmds, err = commandline.ParseCommandTemplate(template)
if test.ExpectedSuccess(t, err) {
if test.ExpectSuccess(t, err) {
expectEquality(t, template, cmds)
}

err = cmds.AddHelp("HELP", map[string]string{})
test.ExpectedSuccess(t, err)
test.ExpectSuccess(t, err)

// adding a second HELP command is not allowed
err = cmds.AddHelp("HELP", map[string]string{})
test.ExpectedFailure(t, err)
test.ExpectFailure(t, err)
}

func TestParser_placeholderLabels(t *testing.T) {
Expand All @@ -299,7 +299,7 @@ func TestParser_placeholderLabels(t *testing.T) {
}

cmds, err = commandline.ParseCommandTemplate(template)
if test.ExpectedSuccess(t, err) {
if test.ExpectSuccess(t, err) {
expectEquivalency(t, cmds)
expectEquality(t, template, cmds)
}
Expand All @@ -319,7 +319,7 @@ func TestParser_optional(t *testing.T) {
t.Errorf("does not parse: %s", err)
}

if test.ExpectedSuccess(t, err) {
if test.ExpectSuccess(t, err) {
expectEquivalency(t, cmds)
expectEquality(t, template, cmds)
}
Expand Down
Loading

0 comments on commit 732c433

Please sign in to comment.