Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the koans more IDE friendly #32

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion about_basics.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package go_koans

func aboutBasics() {
assert(__bool__ == true) // what is truth?
assert(true == true) // what is truth?
assert(__bool__ != false) // in it there is nothing false

var i int = __int__
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module go_koans

go 1.12
33 changes: 1 addition & 32 deletions setup_koans_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,11 @@ package go_koans

import (
"fmt"
"io/ioutil"
"os"
"path"
"runtime"
"strings"
"testing"
)

const (
__string__ string = "impossibly lame value"
__int__ int = -1
__positive_int__ int = 42
__byte__ byte = 255
__bool__ bool = false // ugh
__boolean__ bool = true // oh well
__float32__ float32 = -1.0
__delete_me__ bool = false
)

var __runner__ runner = nil

func TestKoans(t *testing.T) {
test = t
aboutBasics()
aboutStrings()
aboutArrays()
Expand All @@ -47,17 +30,3 @@ func TestKoans(t *testing.T) {

fmt.Printf("\n%c[32;1mYou won life. Good job.%c[0m\n\n", 27, 27)
}

func assert(o bool) {
if !o {
fmt.Printf("\n%c[35m%s%c[0m\n\n", 27, __getRecentLine(), 27)
os.Exit(1)
}
}

func __getRecentLine() string {
_, file, line, _ := runtime.Caller(2)
buf, _ := ioutil.ReadFile(file)
code := strings.TrimSpace(strings.Split(string(buf), "\n")[line-1])
return fmt.Sprintf("%v:%d\n%s", path.Base(file), line, code)
}
37 changes: 37 additions & 0 deletions test-support.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package go_koans

import (
"fmt"
"io/ioutil"
"path"
"runtime"
"strings"
"testing"
)

const (
__string__ string = "impossibly lame value"
__int__ int = -1
__positive_int__ int = 42
__byte__ byte = 255
__bool__ bool = false // ugh
__boolean__ bool = true // oh well
__float32__ float32 = -1.0
__delete_me__ bool = false
)

var __runner__ runner = nil
var test *testing.T

func assert(o bool) {
if !o {
test.Fatalf("\n%c[35m%s%c[0m\n\n", 27, __getRecentLine(), 27)
}
}

func __getRecentLine() string {
_, file, line, _ := runtime.Caller(2)
buf, _ := ioutil.ReadFile(file)
code := strings.TrimSpace(strings.Split(string(buf), "\n")[line-1])
return fmt.Sprintf("%v:%d\n%s", path.Base(file), line, code)
}