File: utils_test.go

package info (click to toggle)
golang-github-audriusbutkevicius-recli 0.0.6-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 128 kB
  • sloc: makefile: 2
file content (43 lines) | stat: -rw-r--r-- 783 bytes parent folder | download
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
// Copyright (C) 2019 Audrius Butkevicius
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

package recli

import (
	"testing"
)

type Inner struct {
	A string `default:"inner"`
	B *DefaultStruct
}

type DefaultStruct struct {
	A string `default:"outer"`
	B []int  `default:"10,20"`
	C Inner
}

func TestSetDefault(t *testing.T) {
	x := &DefaultStruct{}
	x.C.B = x
	err := setDefaults("default", x, nil)
	if err != nil {
		t.Error(err)
	}
	if x.A != "outer" {
		t.Errorf("A")
	}
	if len(x.B) != 2 {
		t.Errorf("B %d", len(x.B))
	}
	if x.C.A != "inner" {
		t.Errorf("C.A")
	}
	if x.C.B.A != "outer" {
		t.Errorf("A loop")
	}
}