1package git23import (4 "context"5 "runtime"6 "testing"78 "github.com/stretchr/testify/assert"9)1011func TestRepository_Grep_Simple(t *testing.T) {12 ctx := context.Background()13 want := []*GrepResult{14 {15 Tree: "HEAD",16 Path: "src/Main.groovy",17 Line: 7,18 Column: 5,19 Text: "int programmingPoints = 10",20 }, {21 Tree: "HEAD",22 Path: "src/Main.groovy",23 Line: 10,24 Column: 33,25 Text: `println "${name} has at least ${programmingPoints} programming points."`,26 }, {27 Tree: "HEAD",28 Path: "src/Main.groovy",29 Line: 11,30 Column: 12,31 Text: `println "${programmingPoints} squared is ${square(programmingPoints)}"`,32 }, {33 Tree: "HEAD",34 Path: "src/Main.groovy",35 Line: 12,36 Column: 12,37 Text: `println "${programmingPoints} divided by 2 bonus points is ${divide(programmingPoints, 2)}"`,38 }, {39 Tree: "HEAD",40 Path: "src/Main.groovy",41 Line: 13,42 Column: 12,43 Text: `println "${programmingPoints} minus 7 bonus points is ${subtract(programmingPoints, 7)}"`,44 }, {45 Tree: "HEAD",46 Path: "src/Main.groovy",47 Line: 14,48 Column: 12,49 Text: `println "${programmingPoints} plus 3 bonus points is ${sum(programmingPoints, 3)}"`,50 },51 }52 got := testrepo.Grep(ctx, "programmingPoints")53 assert.Equal(t, want, got)54}5556func TestRepository_Grep_IgnoreCase(t *testing.T) {57 ctx := context.Background()58 want := []*GrepResult{59 {60 Tree: "HEAD",61 Path: "README.txt",62 Line: 9,63 Column: 36,64 Text: "* git@github.com:matthewmccullough/hellogitworld.git",65 }, {66 Tree: "HEAD",67 Path: "README.txt",68 Line: 10,69 Column: 38,70 Text: "* git://github.com/matthewmccullough/hellogitworld.git",71 }, {72 Tree: "HEAD",73 Path: "README.txt",74 Line: 11,75 Column: 58,76 Text: "* https://matthewmccullough@github.com/matthewmccullough/hellogitworld.git",77 }, {78 Tree: "HEAD",79 Path: "src/Main.groovy",80 Line: 9,81 Column: 10,82 Text: `println "Hello ${name}"`,83 }, {84 Tree: "HEAD",85 Path: "src/main/java/com/github/App.java",86 Line: 4,87 Column: 4,88 Text: " * Hello again",89 }, {90 Tree: "HEAD",91 Path: "src/main/java/com/github/App.java",92 Line: 5,93 Column: 4,94 Text: " * Hello world!",95 }, {96 Tree: "HEAD",97 Path: "src/main/java/com/github/App.java",98 Line: 6,99 Column: 4,100 Text: " * Hello",101 }, {102 Tree: "HEAD",103 Path: "src/main/java/com/github/App.java",104 Line: 13,105 Column: 30,106 Text: ` System.out.println( "Hello World!" );`,107 },108 }109 got := testrepo.Grep(ctx, "Hello", GrepOptions{IgnoreCase: true})110 assert.Equal(t, want, got)111}112113func TestRepository_Grep_ExtendedRegexp(t *testing.T) {114 ctx := context.Background()115 if runtime.GOOS == "darwin" {116 t.Skip("Skipping testing on macOS")117 return118 }119 want := []*GrepResult{120 {121 Tree: "HEAD",122 Path: "src/main/java/com/github/App.java",123 Line: 13,124 Column: 30,125 Text: ` System.out.println( "Hello World!" );`,126 },127 }128 got := testrepo.Grep(ctx, `Hello\sW\w+`, GrepOptions{ExtendedRegexp: true})129 assert.Equal(t, want, got)130}131132func TestRepository_Grep_WordRegexp(t *testing.T) {133 ctx := context.Background()134 want := []*GrepResult{135 {136 Tree: "HEAD",137 Path: "src/main/java/com/github/App.java",138 Line: 5,139 Column: 10,140 Text: ` * Hello world!`,141 },142 }143 got := testrepo.Grep(ctx, "world", GrepOptions{WordRegexp: true})144 assert.Equal(t, want, got)145}