| 1 | package ast |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/robertkrimen/otto/file" |
| 7 | ) |
| 8 | |
| 9 | func TestCommentMap(t *testing.T) { |
| 10 | statement := &EmptyStatement{file.Idx(1)} |
| 11 | comment := &Comment{Begin: 1, Text: "test", Position: LEADING} |
| 12 | |
| 13 | cm := CommentMap{} |
| 14 | cm.AddComment(statement, comment) |
| 15 | |
| 16 | if cm.Size() != 1 { |
| 17 | t.Errorf("the number of comments is %v, not 1", cm.Size()) |
| 18 | } |
| 19 | |
| 20 | if len(cm[statement]) != 1 { |
| 21 | t.Errorf("the number of comments is %v, not 1", cm.Size()) |
| 22 | } |
| 23 | |
| 24 | if cm[statement][0].Text != "test" { |
| 25 | t.Errorf("the text is %v, not \"test\"", cm[statement][0].Text) |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | func TestCommentMap_move(t *testing.T) { |
| 30 | statement1 := &EmptyStatement{file.Idx(1)} |
| 31 | statement2 := &EmptyStatement{file.Idx(2)} |
| 32 | comment := &Comment{Begin: 1, Text: "test", Position: LEADING} |
| 33 | |
| 34 | cm := CommentMap{} |
| 35 | cm.AddComment(statement1, comment) |
| 36 | |
| 37 | if cm.Size() != 1 { |
| 38 | t.Errorf("the number of comments is %v, not 1", cm.Size()) |
| 39 | } |
| 40 | |
| 41 | if len(cm[statement1]) != 1 { |
| 42 | t.Errorf("the number of comments is %v, not 1", cm.Size()) |
| 43 | } |
| 44 | |
| 45 | if len(cm[statement2]) != 0 { |
| 46 | t.Errorf("the number of comments is %v, not 0", cm.Size()) |
| 47 | } |
| 48 | |
| 49 | cm.MoveComments(statement1, statement2, LEADING) |
| 50 | |
| 51 | if cm.Size() != 1 { |
| 52 | t.Errorf("the number of comments is %v, not 1", cm.Size()) |
| 53 | } |
| 54 | |
| 55 | if len(cm[statement2]) != 1 { |
| 56 | t.Errorf("the number of comments is %v, not 1", cm.Size()) |
| 57 | } |
| 58 | |
| 59 | if len(cm[statement1]) != 0 { |
| 60 | t.Errorf("the number of comments is %v, not 0", cm.Size()) |
| 61 | } |
| 62 | } |