-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
17 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,35 @@ | ||
package main | ||
|
||
import ( | ||
"os/exec" | ||
"os/exec" | ||
"testing" | ||
) | ||
|
||
func TestMain(t *testing.T) { | ||
testCommand(t, `echo 'Hello there!' | xo 'i/hello(.*)/Hi$1/'`, | ||
`Hi there! | ||
testCommand(t, `echo 'Hello there!' | xo 'i/hello(.*)/Hi$1/'`, | ||
`Hi there! | ||
`) | ||
testCommand(t, `echo 'Hello! - Bob' | xo 'i/(hello).*?-.*?(\w+)/Why $1, $2!/'`, | ||
`Why Hello, Bob! | ||
testCommand(t, `echo 'Hello! - Bob' | xo 'i/(hello).*?-.*?(\w+)/Why $1, $2!/'`, | ||
`Why Hello, Bob! | ||
`) | ||
testCommand(t, `cat fixtures/servers.yml | xo 'mis/.*?(production):\s*server:\s+([^:\n]+):?(\d+)?.*?user:\s+([^\n]+).*/$4@$2 -p $3?:22/'`, | ||
`user-1@192.168.1.1 -p 1234 | ||
testCommand(t, `cat fixtures/servers.yml | xo 'mis/.*?(production):\s*server:\s+([^:\n]+):?(\d+)?.*?user:\s+([^\n]+).*/$4@$2 -p $3?:22/'`, | ||
`user-1@192.168.1.1 -p 1234 | ||
`) | ||
testCommand(t, `cat fixtures/starwars.txt | xo 'mi/^(\w+):(\s*\[(.*?)\]\s*)?\s*([^\n]+)/$1 said, "$4" in a $3?:normal voice./'`, | ||
`Vader said, "If only you knew the power of the Dark Side. Obi-Wan never told you what happened to your father." in a normal voice. | ||
testCommand(t, `cat fixtures/starwars.txt | xo 'mi/^(\w+):(\s*\[(.*?)\]\s*)?\s*([^\n]+)/$1 said, "$4" in a $3?:normal voice./'`, | ||
`Vader said, "If only you knew the power of the Dark Side. Obi-Wan never told you what happened to your father." in a normal voice. | ||
Luke said, "He told me enough! He told me you killed him!" in a normal voice. | ||
Vader said, "No, I am your father." in a normal voice. | ||
Luke said, "No. No! That's not true! That's impossible!" in a shocked voice. | ||
`) | ||
} | ||
|
||
func testCommand(t *testing.T, cmd string, expected string) { | ||
out, err := exec.Command("bash", "-c", cmd).Output() | ||
if err != nil { | ||
t.Fatalf(err.Error()) | ||
} | ||
result := string(out) | ||
if result != expected { | ||
t.Fatalf("'%s' should be '%s'", result, expected) | ||
} | ||
out, err := exec.Command("bash", "-c", cmd).Output() | ||
if err != nil { | ||
t.Fatalf(err.Error()) | ||
} | ||
result := string(out) | ||
if result != expected { | ||
t.Fatalf("'%s' should be '%s'", result, expected) | ||
} | ||
} |