示例#1
0
func TestRuleThatTriggers(t *testing.T) {
	r := NewRule("^[ \t]*def ([a-z]+)", 1, 0)
	recorder := &fauxRecorder{}

	applied := r.Apply(recorder, "def foo(a, b)", Location{3, 21})

	assert.True(t, applied)
	assert.StringEqual(t, "foo", recorder.name)
	assert.StringEqual(t, "def foo", recorder.def)
	assert.IntEqual(t, 3, recorder.loc.LineCount)
	assert.IntEqual(t, 21, recorder.loc.ByteCount)
}
func TestRubyRuleWithAttrAccessor(t *testing.T) {
	recorder := &fauxRecorder{}
	RubyRules.CheckLine(recorder, "attr_accessor :a, :b", Location{12, 34})

	assertRecorded(t, recorder, "b", "attr_accessor :a, :b", 12, 34)
	assert.IntEqual(t, 2, recorder.count)
	assert.StringEqual(t, "<a><b>", recorder.names)
}
func TestRubyRuleWithClassMethod(t *testing.T) {
	recorder := &fauxRecorder{}
	RubyRules.CheckLine(recorder, "def self.foo()", Location{12, 34})

	assertRecorded(t, recorder, "self.foo", "def self.foo", 12, 34)
	assert.IntEqual(t, 2, recorder.count)
	assert.StringEqual(t, "<foo><self.foo>", recorder.names)
}
示例#4
0
func TestRuleThatDoesNotTrigger(t *testing.T) {
	r := NewRule("^[ \t]*def ([a-z]+)", 1, 0)
	recorder := &fauxRecorder{}

	applied := r.Apply(recorder, "dog = Dog.new", Location{3, 21})

	assert.True(t, !applied)
	assert.StringEqual(t, "", recorder.name)
}
示例#5
0
func TestTagWithNoDefs(t *testing.T) {
	tag := NewTag("empty.go")

	s := StringIo{""}
	tag.WriteOn(&s)

	expected := ""

	assert.StringEqual(t, expected, s.data)
}
示例#6
0
func TestTag(t *testing.T) {
	tag := NewTag("file.go")
	tag.Add("fun", "def fun", Location{10, 123})
	tag.Add("g", "def g", Location{23, 150})

	s := StringIo{""}
	tag.WriteOn(&s)

	defstring :=
		"def fun\x7ffun\x0110,123\n" +
			"def g\x7fg\x0123,150\n"
	expected := "\x0c\n" +
		"file.go," + strconv.Itoa(len(defstring)) + "\n" +
		defstring

	assert.StringEqual(t, expected, s.data)
}
func assertRecorded(t *testing.T, rec *fauxRecorder, methodName, defString string, lines, bytes int) {
	assert.StringEqual(t, methodName, rec.name)
	assert.StringEqual(t, defString, rec.def)
	assert.IntEqual(t, lines, rec.loc.LineCount)
	assert.IntEqual(t, bytes, rec.loc.ByteCount)
}