summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--handlers_test.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/handlers_test.go b/handlers_test.go
new file mode 100644
index 0000000..72d3304
--- /dev/null
+++ b/handlers_test.go
@@ -0,0 +1,31 @@
+package main
+
+import (
+	"fmt"
+	"log"
+	"net/http"
+	"net/http/httptest"
+	"os"
+	"testing"
+)
+
+func logToNull() {
+	hush, err := os.Open("/dev/null")
+	if err != nil {
+		log.Printf("%v\n", err)
+	}
+	log.SetOutput(hush)
+}
+
+func Test_indexHandler(t *testing.T) {
+	logToNull()
+	t.Run("indexHandler", func(t *testing.T) {
+		w := httptest.NewRecorder()
+		req := httptest.NewRequest("GET", "localhost:9001/", nil)
+		indexHandler(w, req)
+		resp := w.Result()
+		if resp.StatusCode != http.StatusOK {
+			t.Errorf(fmt.Sprintf("%v", resp.StatusCode))
+		}
+	})
+}
tle='author Kartik K. Agaram <vc@akkartik.com> 2015-11-11 09:13:40 -0800 committer Kartik K. Agaram <vc@akkartik.com> 2015-11-11 09:17:16 -0800 2426' href='/akkartik/mu/commit/factorial.mu?h=main&id=322416056beae917b0877f984ccc2b4b930a14ce'>32241605 ^
b96af395 ^

ce87c19e ^

bc643692 ^
08b48a8d ^
c1d92c9d ^
ce87c19e ^

32241605 ^
b96af395 ^
08b48a8d ^
b96af395 ^


bc643692 ^
b96af395 ^
bafc7192 ^
b96af395 ^


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33


                                             
             
                         
                          


 
                                            
             
                  

                     

                               
           
   
                             

                                 
                                 
 
 


                         
                           
   
                         


            
# example program: compute the factorial of 5

recipe main [
  local-scope
  x:number <- factorial 5
  $print [result: ], x, [ 
]
]

recipe factorial n:number -> result:number [
  local-scope
  load-ingredients
  {
    # if n=0 return 1
    zero?:boolean <- equal n, 0
    break-unless zero?
    reply 1
  }
  # return n * factorial(n-1)
  x:number <- subtract n, 1
  subresult:number <- factorial x
  result <- multiply subresult, n
]

# unit test
scenario factorial-test [
  run [
    1:number <- factorial 5
  ]
  memory-should-contain [
    1 <- 120
  ]
]