File: compression_test.go

package info (click to toggle)
syncthing 0.14.18%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 7,388 kB
  • ctags: 4,608
  • sloc: xml: 781; sh: 271; makefile: 45
file content (49 lines) | stat: -rw-r--r-- 941 bytes parent folder | download | duplicates (2)
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
// Copyright (C) 2015 The Protocol Authors.

package protocol

import "testing"

func TestCompressionMarshal(t *testing.T) {
	uTestcases := []struct {
		s string
		c Compression
	}{
		{"true", CompressMetadata},
		{"false", CompressNever},
		{"never", CompressNever},
		{"metadata", CompressMetadata},
		{"always", CompressAlways},
		{"whatever", CompressMetadata},
	}

	mTestcases := []struct {
		s string
		c Compression
	}{
		{"never", CompressNever},
		{"metadata", CompressMetadata},
		{"always", CompressAlways},
	}

	var c Compression
	for _, tc := range uTestcases {
		err := c.UnmarshalText([]byte(tc.s))
		if err != nil {
			t.Error(err)
		}
		if c != tc.c {
			t.Errorf("%s unmarshalled to %d, not %d", tc.s, c, tc.c)
		}
	}

	for _, tc := range mTestcases {
		bs, err := tc.c.MarshalText()
		if err != nil {
			t.Error(err)
		}
		if s := string(bs); s != tc.s {
			t.Errorf("%d marshalled to %q, not %q", tc.c, s, tc.s)
		}
	}
}