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) }
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) }