json icon indicating copy to clipboard operation
json copied to clipboard

Unexpected behaviour of internal type `stack'

Open dolmen opened this issue 2 years ago • 0 comments

func TestBoolStack(t *testing.T) {
	var bs stack
	bs.push(true)
	bs.push(false)
	bs.push(true)
	for i := len(bs); i > 0; i-- {
		t.Log(bs.len(), bs.pop())
	}
}

Output:

=== RUN   TestBoolStack
    decoder_test.go:229: 3 false
    decoder_test.go:229: 2 true
    decoder_test.go:229: 1 false
--- PASS: TestBoolStack (0.00s)

The output doesn't match the reversed input. This is not what I expect from a stack with methods push and pop. Is it on purpose? I guess not, but there is no comment on the stack type to tell otherwise.

dolmen avatar Jan 24 '23 17:01 dolmen