-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhanjie_test.go
97 lines (86 loc) · 2.04 KB
/
hanjie_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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package hanjie_test
import (
"bytes"
"strings"
"testing"
"github.com/alexeyco/hanjie"
"github.com/alexeyco/hanjie/ast"
"github.com/stretchr/testify/assert"
)
var expectedPuzzleSet = &ast.PuzzleSet{
{
ID: "id",
Source: "https://foo.bar",
Author: &ast.Author{
Name: "John Doe",
ID: "johnDoe",
},
Copyright: "© John Doe",
Title: "Puzzle",
Description: "Very beautiful puzzle",
Background: ast.Char('.'),
Colors: ast.Colors{
ast.Char('.'): ast.Color{R: 255, G: 255, B: 255},
ast.Char('x'): ast.Color{},
},
Clue: ast.Clue{
Columns: []ast.Line{
{
{Color: ast.Char('x'), Count: 2},
},
{
{Color: ast.Char('x'), Count: 1}, {Color: ast.Char('x'), Count: 1},
},
{
{Color: ast.Char('x'), Count: 2},
},
},
Rows: []ast.Line{
{
{Color: ast.Char('x'), Count: 2},
},
{
{Color: ast.Char('x'), Count: 1}, {Color: ast.Char('x'), Count: 1},
},
{
{Color: ast.Char('x'), Count: 2},
},
},
},
Goal: &ast.Goal{
{ast.Char('x'), ast.Char('x'), ast.Char('.')},
{ast.Char('x'), ast.Char('.'), ast.Char('x')},
{ast.Char('.'), ast.Char('x'), ast.Char('x')},
},
},
}
var expectedString = `- id: id
source: https://foo.bar
author:
name: John Doe
id: johnDoe
copyright: '© John Doe'
title: Puzzle
description: Very beautiful puzzle
background: .
colors:
.: '#ffffff'
x: '#000000'
clue:
columns: [[{color: x, count: 2}], [{color: x, count: 1}, {color: x, count: 1}], [{color: x, count: 2}]]
rows: [[{color: x, count: 2}], [{color: x, count: 1}, {color: x, count: 1}], [{color: x, count: 2}]]
goal: [[x, x, .], [x, ., x], [., x, x]]
`
func TestRead(t *testing.T) {
t.Parallel()
actual, err := hanjie.Read(strings.NewReader(expectedString))
assert.NoError(t, err)
assert.Equal(t, expectedPuzzleSet, actual)
}
func TestWrite(t *testing.T) {
t.Parallel()
var buf bytes.Buffer
err := hanjie.Write(&buf, expectedPuzzleSet)
assert.NoError(t, err)
assert.Equal(t, expectedString, buf.String())
}