File: print_test.go

package info (click to toggle)
golang-github-hanwen-go-fuse 2.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,584 kB
  • sloc: cpp: 78; sh: 47; makefile: 16
file content (56 lines) | stat: -rw-r--r-- 1,359 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
50
51
52
53
54
55
56
// Copyright 2023 the Go-FUSE Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package fuse

import (
	"testing"
)

func init() {
	isTest = true
}

// verify that flagString always formats flags in the same order.
func TestFlagStringOrder(t *testing.T) {
	var flags int64 = CAP_ASYNC_READ | CAP_SPLICE_WRITE | CAP_READDIRPLUS | CAP_MAX_PAGES | CAP_EXPLICIT_INVAL_DATA
	want := "ASYNC_READ,SPLICE_WRITE,READDIRPLUS,MAX_PAGES,EXPLICIT_INVAL_DATA"
	// loop many times to check for sure the order is untied from map iteration order
	for i := 0; i < 100; i++ {
		have := flagString(initFlagNames, flags, "")
		if have != want {
			t.Fatalf("flagString:\nhave: %q\nwant: %q", have, want)
		}
	}
}

// verify how flagString handles provided default.
func TestFlagStringDefault(t *testing.T) {
	names := newFlagNames([]flagNameEntry{
		{1, "AAA"},
		{2, "BBB"},
		{4, "CCC"},
	})

	testv := []struct {
		flags int64
		def   string
		strok string
	}{
		{0, "", ""},
		{0, "X", "X"},
		{1, "X", "AAA"},
		{5, "X", "AAA,CCC"},
		{8, "X", "0x8"},
		{9, "X", "AAA,0x8"},
	}

	for _, test := range testv {
		str := flagString(names, test.flags, test.def)
		if str != test.strok {
			t.Errorf("flagString(%x, %q) -> got %q ;  want %q",
				test.flags, test.def, str, test.strok)
		}
	}
}