-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
47 lines (36 loc) · 1.06 KB
/
main_test.go
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"ascii-art-output/functions"
"fmt"
"os"
"strings"
"testing"
)
func TestMainFunction(t *testing.T) {
outputFileName := "output.txt" // Specify the default value for the flag as specified in main.go
// Check if the file exists
_, err := os.Stat(outputFileName)
if err != nil {
t.Fatalf("File %s does not exist", outputFileName)
}
//Read the file if it exists
expectedContent, err := os.ReadFile(outputFileName)
if err != nil {
t.Fatalf("Failed to read expected output file '%s': %v", outputFileName, err)
}
expectedContentStr := string(expectedContent)
//Read the default banner file specified in main.go
file, err := os.ReadFile("standard.txt")
if err != nil {
fmt.Println("Error: ", err)
os.Exit(1)
}
var fileLine []string
fileLine = strings.Split(string(file), "\n")
//Specify a string input that can be entered by the user
input := "hello"
result := functions.AsciiArt(input, fileLine)
if result != expectedContentStr {
t.Errorf("For input:\n'%s'\nExpected:\n%s\n but got:\n%s", input, expectedContentStr, result)
}
}