コード例 #1
0
ファイル: ast_test.go プロジェクト: sbinet/fubsy
func Test_ASTInline_Equal(t *testing.T) {
	node1 := &ASTInline{}
	node2 := &ASTInline{}
	assert.True(t, node1.Equal(node1),
		"ASTInline not equal to itself")
	assert.True(t, node1.Equal(node2),
		"empty ASTInlines not equal")

	node1.lang = "foo"
	node2.lang = "bar"
	assert.False(t, node1.Equal(node2),
		"ASTInlines equal despite different lang")

	node2.lang = "foo"
	assert.True(t, node1.Equal(node2),
		"ASTInlines not equal")

	node1.content = "hello\nworld\n"
	node2.content = "hello\nworld"
	assert.False(t, node1.Equal(node2),
		"ASTInlines equal despite different content")

	node2.content += "\n"
	assert.True(t, node1.Equal(node2),
		"ASTInlines not equal")
}
コード例 #2
0
ファイル: listnode_test.go プロジェクト: sbinet/fubsy
func Test_ListNode_basics(t *testing.T) {
	node0 := NewStubNode("foo")
	node1 := NewStubNode("bar baz")
	node2 := NewStubNode("qux")
	list1 := newListNode(node0, node1, node2)
	assert.Equal(t, "ListNode", list1.Typename())
	assert.Equal(t, "foo,bar baz,qux", list1.Name())
	assert.Equal(t, `["foo", "bar baz", "qux"]`, list1.String())
	assert.Equal(t, "foo,bar baz,qux", list1.ValueString())
	assert.Equal(t, "foo 'bar baz' qux", list1.CommandString())

	expect1 := []types.FuObject{node0, node1, node2}
	assert.Equal(t, expect1, list1.List())

	expect2 := []Node{node0, node1, node2}
	assert.Equal(t, expect2, list1.Nodes())

	list2 := newListNode(node0, node1, node2)
	assert.True(t, list1.Equal(list2))

	list3 := newListNode(node1, node0, node2)
	assert.False(t, list1.Equal(list3))

	list4 := list3.copy().(*ListNode)
	assert.False(t, list3 == list4)
	assert.True(t, list3.Equal(list4))
}
コード例 #3
0
ファイル: game_test.go プロジェクト: jneander/tic-tac-toe-go
func TestGame_IsOver(t *testing.T) {
	var game Game = NewGame()
	var board = game.Board()

	t.Log("New Game is not over")
	assert.False(t, game.IsOver())

	t.Log("Game with two-in-a-row is not over")
	AddMarks(board, "X", 4, 8)
	assert.False(t, game.IsOver())

	t.Log("Game with three-in-a-row \"X\" is over")
	board.Mark(0, "X")
	assert.True(t, game.IsOver())

	t.Log("Game with three-in-a-row \"O\" is over")
	board.Reset()
	AddMarks(board, "O", 2, 4, 6)
	assert.True(t, game.IsOver())

	t.Log("Game with three-in-a-row mismatched is not over")
	board.Mark(2, "X")
	assert.False(t, game.IsOver())

	t.Log("Game with nearly-full, non-winning board is not over")
	board.Reset()
	AddMarks(board, "X", 0, 1, 4, 5)
	AddMarks(board, "O", 2, 3, 7, 8)
	assert.False(t, game.IsOver())

	t.Log("Game with full, non-winning board is over")
	board.Mark(6, "X")
	assert.True(t, game.IsOver())
}
コード例 #4
0
func TestSpResult(t *testing.T) {
	r := NewSpResult()
	assert.Equal(t, -1, r.status)
	assert.Equal(t, -1, r.currentResult)
	assert.False(t, r.HasOutputParams())
	assert.False(t, r.HasResults())
	assert.False(t, r.NextResult())
	assert.Nil(t, r.Result())
}
コード例 #5
0
ファイル: namespace_test.go プロジェクト: sbinet/fubsy
func Test_ValueMap_basics(t *testing.T) {
	ns := NewValueMap()
	val, ok := ns.Lookup("foo")
	assert.False(t, ok)
	val, ok = ns.Lookup("bar")
	assert.False(t, ok)

	ns.Assign("foo", MakeFuString("blurp"))
	val, ok = ns.Lookup("foo")
	assert.True(t, ok)
	assert.Equal(t, "blurp", val.ValueString())
	val, ok = ns.Lookup("bar")
	assert.False(t, ok)
}
コード例 #6
0
ファイル: ppu_test.go プロジェクト: samfoo/gones
func TestSetMasks(t *testing.T) {
	m := new(Masks)

	assert.False(t, m.Grayscale)
	m.Set(0x01)
	assert.True(t, m.Grayscale)

	assert.False(t, m.ShowBackgroundLeft)
	m.Set(0x02)
	assert.True(t, m.ShowBackgroundLeft)

	assert.False(t, m.ShowSpritesLeft)
	m.Set(0x04)
	assert.True(t, m.ShowSpritesLeft)

	assert.False(t, m.ShowBackground)
	m.Set(0x08)
	assert.True(t, m.ShowBackground)

	assert.False(t, m.ShowSprites)
	m.Set(0x10)
	assert.True(t, m.ShowSprites)

	assert.False(t, m.IntenseReds)
	m.Set(0x20)
	assert.True(t, m.IntenseReds)

	assert.False(t, m.IntenseGreens)
	m.Set(0x40)
	assert.True(t, m.IntenseGreens)

	assert.False(t, m.IntenseBlues)
	m.Set(0x80)
	assert.True(t, m.IntenseBlues)
}
コード例 #7
0
ファイル: findernode_test.go プロジェクト: sbinet/fubsy
// hmmmm: interface-wise, this tests that FinderNode.Add() returns an
// object whose CommandString() behaves sensibly... but in
// implementation terms, it's really a test of FuList.CommandString()
func Test_FinderNode_Add_CommandString(t *testing.T) {
	finder1 := NewFinderNode("*.c", "*.h")
	finder2 := NewFinderNode("doc/???.txt")
	finder3 := NewFinderNode()

	sum1, err := finder1.Add(finder2)
	assert.Nil(t, err)
	assert.Equal(t, "'*.c' '*.h' 'doc/???.txt'", sum1.CommandString())

	sum2, err := finder3.Add(sum1)
	assert.Nil(t, err)
	assert.Equal(t, "'*.c' '*.h' 'doc/???.txt'", sum2.CommandString())

	assert.False(t, sum1.Equal(sum2))

	sum2b, err := finder3.Add(sum1)
	assert.Nil(t, err)
	assert.True(t, sum2.Equal(sum2b),
		"expected equal ListNodes:\nsum2  = %T %v\nsum2b = %T %v",
		sum2, sum2, sum2b, sum2b)

	// This is a silly thing to do, and perhaps we should filter out
	// the duplicate patterns... but I don't think so. If the user
	// constructs something silly, we do something silly.
	sum3, err := sum1.Add(sum2)
	assert.Nil(t, err)
	assert.Equal(t,
		"'*.c' '*.h' 'doc/???.txt' '*.c' '*.h' 'doc/???.txt'",
		sum3.CommandString())
}
コード例 #8
0
ファイル: conn_test.go プロジェクト: upstartmobile/gofreetds
func TestConnect(t *testing.T) {
	conn := ConnectToTestDb(t)
	assert.NotNil(t, conn)
	defer conn.Close()
	assert.True(t, conn.isLive())
	assert.False(t, conn.isDead())
}
コード例 #9
0
ファイル: mapping_test.go プロジェクト: smw/goweb
func TestMapStaticFile(t *testing.T) {

	codecService := new(codecservices.WebCodecService)
	h := NewHttpHandler(codecService)

	h.MapStaticFile("/static-file", "/location/of/static-file")

	assert.Equal(t, 1, len(h.HandlersPipe()))

	staticHandler := h.HandlersPipe()[0].(*PathMatchHandler)

	if assert.Equal(t, 1, len(staticHandler.HttpMethods)) {
		assert.Equal(t, goweb_http.MethodGet, staticHandler.HttpMethods[0])
	}

	var ctx context.Context
	var willHandle bool

	ctx = context_test.MakeTestContextWithPath("/static-file")
	willHandle, _ = staticHandler.WillHandle(ctx)
	assert.True(t, willHandle, "Static handler should handle")

	ctx = context_test.MakeTestContextWithPath("static-file")
	willHandle, _ = staticHandler.WillHandle(ctx)
	assert.True(t, willHandle, "Static handler should handle")

	ctx = context_test.MakeTestContextWithPath("static-file/")
	willHandle, _ = staticHandler.WillHandle(ctx)
	assert.True(t, willHandle, "Static handler should handle")

	ctx = context_test.MakeTestContextWithPath("static-file/something-else")
	willHandle, _ = staticHandler.WillHandle(ctx)
	assert.False(t, willHandle, "Static handler NOT should handle")

}
コード例 #10
0
ファイル: mock.go プロジェクト: sbinet/fubsy
// AssertNotCalled asserts that the method was not called.
func (m *Mock) AssertNotCalled(t *testing.T, methodName string, arguments ...interface{}) bool {
	if !assert.False(t, m.methodWasCalled(methodName, arguments), fmt.Sprintf("The \"%s\" method was called with %d argument(s), but should NOT have been.", methodName, len(arguments))) {
		t.Logf("%s", m.ExpectedCalls)
		return false
	}
	return true
}
コード例 #11
0
ファイル: path_match_handler_test.go プロジェクト: smw/goweb
func TestPathMatchHandler_BreakCurrentPipeline(t *testing.T) {

	pathPattern, _ := paths.NewPathPattern("collection/{id}/name")
	h := NewPathMatchHandler(pathPattern, HandlerExecutionFunc(func(c context.Context) error {
		return nil
	}))
	h.BreakCurrentPipeline = true

	ctx1 := context_test.MakeTestContextWithPath("/collection/123/name")

	breakCurrentPipeline, _ := h.Handle(ctx1)

	assert.True(t, breakCurrentPipeline)

	h = NewPathMatchHandler(pathPattern, HandlerExecutionFunc(func(c context.Context) error {
		return nil
	}))
	h.BreakCurrentPipeline = false

	ctx1 = context_test.MakeTestContextWithPath("/collection/123/name")

	breakCurrentPipeline, _ = h.Handle(ctx1)

	assert.False(t, breakCurrentPipeline)

}
コード例 #12
0
ファイル: cpu_nmi_test.go プロジェクト: samfoo/gones
func TestInterruptingNMISetsNMI(t *testing.T) {
	p := NewCPU()

	assert.False(t, p.nmi.Occurred)
	p.Interrupt(NMI)
	assert.True(t, p.nmi.Occurred)
}
コード例 #13
0
ファイル: builtins_test.go プロジェクト: sbinet/fubsy
func Test_BuiltinList(t *testing.T) {
	blist := BuiltinList{}
	fn, ok := blist.Lookup("foo")
	assert.False(t, ok)
	assert.Nil(t, fn)

	callable := types.NewFixedFunction("foo", 3, nil)
	blist.builtins = append(blist.builtins, callable)
	fn, ok = blist.Lookup("foo")
	assert.True(t, ok)
	assert.Equal(t, callable, fn)

	blist.builtins = append(
		blist.builtins, types.NewFixedFunction("bar", 0, nil))
	blist.builtins = append(
		blist.builtins, types.NewFixedFunction("bop", 0, nil))
	blist.builtins = append(
		blist.builtins, types.NewFixedFunction("bam", 0, nil))
	blist.builtins = append(
		blist.builtins, types.NewFixedFunction("pow", 0, nil))

	assert.Equal(t, 5, blist.NumBuiltins())
	actual := make([]string, 0, 5)
	visit := func(name string, code types.FuObject) error {
		actual = append(actual, name)
		if name == "bam" {
			return errors.New("bam!")
		}
		return nil
	}
	err := blist.ForEach(visit)
	assert.Equal(t, []string{"foo", "bar", "bop", "bam"}, actual)
	assert.Equal(t, "bam!", err.Error())
}
コード例 #14
0
func test_AccessChannel(t *testing.T, err_msg string, timer NetAccessRule, timeout time.Duration) (err error) {
	timeout_chan := make(chan struct{}, 1)
	timeout_func := func() {
		time.Sleep(timeout)
		close(timeout_chan)

	}
	go timeout_func()
	i := 0
	for i < 5 {
		access_chan := timer.AccessChannel()
		break_loop := false
		for !break_loop {
			select {
			case <-timeout_chan:
				return errors.New(fmt.Sprintf("Access channel timed out at iteration %i", i))
			case _, ok := <-access_chan:
				assert.False(t, ok, err_msg)
				i++
				break_loop = true
			}
		}
	}
	return nil
}
コード例 #15
0
ファイル: basictypes_test.go プロジェクト: sbinet/fubsy
func Test_FuString_Lookup(t *testing.T) {
	// strings have no attributes
	s := MakeFuString("blah")
	val, ok := s.Lookup("foo")
	assert.Nil(t, val)
	assert.False(t, ok)
}
コード例 #16
0
ファイル: path_match_handler_test.go プロジェクト: smw/goweb
func TestPathMatchHandler(t *testing.T) {

	pathPattern, _ := paths.NewPathPattern("collection/{id}/name")
	var called bool = false
	h := NewPathMatchHandler(pathPattern, HandlerExecutionFunc(func(c context.Context) error {
		called = true
		return nil
	}))

	ctx1 := context_test.MakeTestContextWithPath("/collection/123/name")
	will, _ := h.WillHandle(ctx1)
	assert.True(t, will)
	h.Handle(ctx1)
	assert.True(t, called, "Method should be called")
	assert.Equal(t, "123", ctx1.Data().Get(context.DataKeyPathParameters).(objects.Map).Get("id"))

	ctx2 := context_test.MakeTestContextWithPath("/collection")
	will, _ = h.WillHandle(ctx2)
	assert.False(t, will)
	assert.Nil(t, ctx2.Data().Get(context.DataKeyPathParameters))

	h.BreakCurrentPipeline = true
	shouldStop, handleErr := h.Handle(ctx2)
	assert.Nil(t, handleErr)
	assert.True(t, shouldStop)
	assert.True(t, called, "Handler func should get called")

}
コード例 #17
0
ファイル: namespace_test.go プロジェクト: sbinet/fubsy
func Test_ValueStack_Assign(t *testing.T) {
	ns0 := NewValueMap()
	stack := NewValueStack()
	assert.Equal(t, 0, len(stack))
	stack.Push(ns0)
	assert.Equal(t, 1, len(stack))

	val1 := MakeFuString("hello")
	val2 := MakeFuString("world")
	val3 := MakeFuString("fnord")

	stack.Assign("foo", val1)
	val, ok := stack.Lookup("foo")
	assert.True(t, ok)
	assert.True(t, val.Equal(val1))
	stack.Assign("foo", val2)
	val, ok = stack.Lookup("foo")
	assert.True(t, ok)
	assert.True(t, val.Equal(val2))

	ns1 := NewValueMap()
	stack.Push(ns1)
	assert.Equal(t, 2, len(stack))
	stack.Assign("bar", val1)
	stack.Assign("foo", val3)

	// make sure we can get the new values out of the stack
	val, ok = stack.Lookup("bar")
	assert.True(t, val.Equal(val1))
	val, ok = stack.Lookup("foo")
	assert.True(t, val.Equal(val3))

	// peek under the hood and make sure each one was added to the
	// right namespace: bar is a new name, so it will be in the
	// innermost (last) namespace
	val, ok = ns1.Lookup("bar")
	assert.True(t, val.Equal(val1))
	val, ok = ns0.Lookup("bar")
	assert.False(t, ok)

	// foo already existed in an enclosing namespace, so Assign()
	// replaced it there
	val, ok = ns0.Lookup("foo")
	assert.True(t, val.Equal(val3))
	val, ok = ns1.Lookup("foo")
	assert.False(t, ok)
}
コード例 #18
0
func TestResultNext(t *testing.T) {
	r := testResult()
	assert.Equal(t, len(r.Rows), 3)
	assert.True(t, r.Next())
	assert.True(t, r.Next())
	assert.True(t, r.Next())
	assert.False(t, r.Next())
}
コード例 #19
0
func TestfuzzyContains(t *testing.T) {
	min := 50
	max := 100
	rect := image.Rect(min, min, max, max)

	assert.False(t, fuzzyContains(&rect, image.Pt(0, 0)))

	coord1 := min - fuzzyness
	assert.True(t, fuzzyContains(&rect, image.Pt(coord1, coord1)))

	assert.True(t, fuzzyContains(&rect, image.Pt(75, 75)))

	coord2 := max + fuzzyness
	assert.True(t, fuzzyContains(&rect, image.Pt(coord2, coord2)))

	assert.False(t, fuzzyContains(&rect, image.Pt(150, 150)))
}
コード例 #20
0
ファイル: path_pattern_test.go プロジェクト: smw/goweb
func TestPathPattern_GetPathMatch_Edges(t *testing.T) {

	// everything
	gp, _ := NewPathPattern(MatchAllPaths)
	assert.True(t, gp.GetPathMatch(NewPath("/people/123/books")).Matches)
	assert.True(t, gp.GetPathMatch(NewPath("/people")).Matches)
	assert.True(t, gp.GetPathMatch(NewPath("/")).Matches)
	assert.True(t, gp.GetPathMatch(NewPath("")).Matches)

	// root
	gp, _ = NewPathPattern("/")
	assert.True(t, gp.GetPathMatch(NewPath("/")).Matches)
	assert.True(t, gp.GetPathMatch(NewPath("")).Matches)
	assert.False(t, gp.GetPathMatch(NewPath("/people/123/books")).Matches)
	assert.False(t, gp.GetPathMatch(NewPath("/people")).Matches)

}
コード例 #21
0
ファイル: mock_test.go プロジェクト: sbinet/fubsy
func Test_Arguments_Is(t *testing.T) {

	var args Arguments = []interface{}{"string", 123, true}

	assert.True(t, args.Is("string", 123, true))
	assert.False(t, args.Is("wrong", 456, false))

}
コード例 #22
0
ファイル: ppu_test.go プロジェクト: samfoo/gones
func TestPPUReadingPPUSTATUSSetsVBlanksStartedToFalse(t *testing.T) {
	p := NewPPU()
	p.Status.VBlankStarted = true

	p.Read(PPUSTATUS)

	assert.False(t, p.Status.VBlankStarted)
}
コード例 #23
0
func TestExecSpReturnValue(t *testing.T) {
	conn := ConnectToTestDb(t)
	err := createProcedure(conn, "test_return_value", " as return 123")
	assert.Nil(t, err)
	rst, err := conn.ExecSp("test_return_value")
	assert.Nil(t, err)
	assert.False(t, rst.HasResults())
	assert.Equal(t, 123, rst.Status())
}
コード例 #24
0
ファイル: findernode_test.go プロジェクト: sbinet/fubsy
func Test_FinderNode_Equal(t *testing.T) {
	finder1 := NewFinderNode("*.c", "*.h")
	finder2 := NewFinderNode("*.c", "*.h")
	finder3 := NewFinderNode("*.h", "*.c")

	assert.True(t, finder1.Equal(finder1))
	assert.True(t, finder1.Equal(finder2))
	assert.False(t, finder1.Equal(finder3))
}
コード例 #25
0
ファイル: game_test.go プロジェクト: jneander/tic-tac-toe-go
func TestGame_IsValidMove(t *testing.T) {
	var game = NewGame()
	var board = game.Board()

	t.Log("#IsValidMove returns true if the selected space is blank")
	assert.True(t, game.IsValidMove(1))
	assert.True(t, game.IsValidMove(2))

	t.Log("#IsValidMove returns true if the selected space is blank")
	board.Mark(1, "X")
	board.Mark(2, "O")
	assert.False(t, game.IsValidMove(1))
	assert.False(t, game.IsValidMove(2))

	t.Log("#IsValidMove returns false if the provided index is out of range")
	assert.False(t, game.IsValidMove(-1))
	assert.False(t, game.IsValidMove(9))
}
コード例 #26
0
func TestExecSpInputParams(t *testing.T) {
	conn := ConnectToTestDb(t)
	err := createProcedure(conn, "test_input_params", "@p1 int = 0, @p2 int, @p3 as varchar(10), @p4 datetime, @p5 varbinary(10) = null as select @p1 = @p1 + @p2; return @p1")
	assert.Nil(t, err)
	rst, err := conn.ExecSp("test_input_params", 123, 234, "pero", time.Now(), []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0})
	assert.Nil(t, err)
	assert.False(t, rst.HasResults())
	assert.Equal(t, 357, rst.Status())
}
コード例 #27
0
ファイル: flags_test.go プロジェクト: jessereynolds/coco
func TestNoBool(t *testing.T) {
	fg := newFlagGroup()
	f := fg.Flag("b", "").Default("true")
	b := f.Bool()
	fg.init()
	tokens := Tokenize([]string{"--no-b"})
	_, err := fg.parse(tokens, false)
	assert.NoError(t, err)
	assert.False(t, *b)
}
コード例 #28
0
ファイル: ppu_test.go プロジェクト: samfoo/gones
func TestPPUStepOnScanlineNegAndFirstCycleClearVBlankStarted(t *testing.T) {
	p := NewPPU()
	p.Scanline = -1
	p.Cycle = 1
	p.VBlankStarted = true

	p.Step()

	assert.False(t, p.Status.VBlankStarted)
}
コード例 #29
0
ファイル: ppu_test.go プロジェクト: samfoo/gones
func TestPPUStepOnScanlineNegFirstCycleClearsSprite0Hit(t *testing.T) {
	p := NewPPU()
	p.Scanline = -1
	p.Status.Sprite0Hit = true
	p.Cycle = 1

	p.Step()

	assert.False(t, p.Status.Sprite0Hit)
}
コード例 #30
0
ファイル: eval_test.go プロジェクト: Gwill/go-R
func TestEval(t *testing.T) {
	assert.Equal(t, 1, Init())
	r, err := Eval("1+3*4")
	assert.Nil(t, err)
	assert.True(t, r.IsNumeric())
	assert.False(t, r.IsComplex())
	assert.Panics(t, func() { r.AsComplex() })
	num := r.AsNumeric()
	assert.Equal(t, 1, num.Len())
	assert.Equal(t, 13, num.Get(0))

	r = EvalOrDie("sqrt(-2+0i)")
	assert.False(t, r.IsNumeric())
	assert.True(t, r.IsComplex())
	assert.Panics(t, func() { r.AsNumeric() })
	cpl := r.AsComplex()
	assert.Equal(t, 1, cpl.Len())
	assert.Equal(t, complex(0, math.Sqrt(2)), cpl.Get(0))
}