MCPcopy
hub / github.com/bettercap/bettercap / TestCapletEvalCommentAtStartOfLine

Function TestCapletEvalCommentAtStartOfLine

caplets/caplet_test.go:224–266  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

222}
223
224func TestCapletEvalCommentAtStartOfLine(t *testing.T) {
225 tempFile, err := ioutil.TempFile("", "test-*.cap")
226 if err != nil {
227 t.Fatal(err)
228 }
229 defer os.Remove(tempFile.Name())
230 tempFile.Close()
231
232 cap := NewCaplet("test", tempFile.Name(), 100)
233 cap.Code = []string{
234 "# comment",
235 " # not a comment (has space before #)",
236 " # not a comment (has tab before #)",
237 "command # inline comment",
238 }
239
240 var gotLines []string
241 err = cap.Eval(nil, func(line string) error {
242 gotLines = append(gotLines, line)
243 return nil
244 })
245
246 if err != nil {
247 t.Errorf("unexpected error: %v", err)
248 }
249
250 expectedLines := []string{
251 " # not a comment (has space before #)",
252 " # not a comment (has tab before #)",
253 "command # inline comment",
254 }
255
256 if len(gotLines) != len(expectedLines) {
257 t.Errorf("got %d lines, want %d", len(gotLines), len(expectedLines))
258 return
259 }
260
261 for i, line := range gotLines {
262 if line != expectedLines[i] {
263 t.Errorf("line %d: got %q, want %q", i, line, expectedLines[i])
264 }
265 }
266}
267
268func TestCapletEvalArgvSubstitutionEdgeCases(t *testing.T) {
269 tests := []struct {

Callers

nothing calls this directly

Calls 6

EvalMethod · 0.95
NewCapletFunction · 0.85
NameMethod · 0.65
FatalMethod · 0.45
RemoveMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected