Exemplo n.º 1
0
func TestMovetoStart(t *testing.T) {
	path, err := svg.NewPath("10,20")
	expectedError := "Path data does not start with a moveto command: 10,20"

	if !(path == nil && err.Error() == expectedError) {
		t.Errorf("Path: expected %v, actual %v\n", expectedError, err)
	}
}
Exemplo n.º 2
0
func TestParamNumberInPath(t *testing.T) {
	path, err := svg.NewPath("M 10 20 30 Z")
	expectedError := "Incorrect number of parameters for M"

	if !(path == nil && err.Error() == expectedError) {
		t.Errorf("Path: expected %v, actual %v\n", expectedError, err)
	}
}
Exemplo n.º 3
0
func testPathCommands(t *testing.T, cases []struct {
	d        string
	commands []*svg.PathCommand
}) {
	for _, test := range cases {
		path, err := svg.NewPath(test.d)
		if err != nil {
			t.Errorf("Path: unexpected error: %v\n", err)
		}

		for i, command := range test.commands {
			if !command.Equals(path.Commands[i]) {
				t.Errorf("Path: expected %v, actual %v\n", command, path.Commands[i])
			}
		}
	}
}
Exemplo n.º 4
0
func ExamplePath_Subpaths() {
	data := "M50,50 A30,30 0 0,1 35,20 m110,110 l100,0"
	path, _ := svg.NewPath(data)
	subpaths := path.Subpaths()

	fmt.Printf("Number of subpaths: %d\n", len(subpaths))
	for i, subpath := range subpaths {
		fmt.Printf("Path %d:", i)
		for _, command := range subpath.Commands {
			fmt.Printf(" %v", command)
		}
		fmt.Println()
	}

	// Output:
	// Number of subpaths: 2
	// Path 0: &{M [50 50]} &{A [30 30 0 0 1 35 20]}
	// Path 1: &{m [110 110]} &{l [100 0]}
}
Exemplo n.º 5
0
func TestSubpaths(t *testing.T) {
	var testCases = []struct {
		d        string
		subpaths []*svg.Path
	}{
		{
			"M 10,20 30,40 Z L 35,45 Z",
			[]*svg.Path{
				{
					Commands: []*svg.PathCommand{
						{Symbol: "M", Params: []float64{10, 20}},
						{Symbol: "L", Params: []float64{30, 40}},
						{Symbol: "Z", Params: []float64{}},
					},
				},
				{
					Commands: []*svg.PathCommand{
						{Symbol: "M", Params: []float64{10, 20}},
						{Symbol: "L", Params: []float64{35, 45}},
						{Symbol: "Z", Params: []float64{}},
					},
				},
			},
		},
	}

	for _, test := range testCases {
		path, err := svg.NewPath(test.d)
		if err != nil {
			t.Errorf("Path: unexpected error: %v\n", err)
		}

		subpaths := path.Subpaths()
		for i, subpath := range test.subpaths {
			if !subpath.Equals(subpaths[i]) {
				t.Errorf("Path: expected %v, actual %v\n", subpath, subpaths[i])
			}
		}
	}
}