MCPcopy Create free account
hub / github.com/OpenPrinting/goipp / TestValueString

Function TestValueString

value_test.go:626–675  ·  view source on GitHub ↗

TestValueString rests Value.String method for various kinds of the Value

(t *testing.T)

Source from the content-addressed store, hash-verified

624// TestValueString rests Value.String method for various
625// kinds of the Value
626func TestValueString(t *testing.T) {
627 loc1 := time.FixedZone("UTC+3:30", 3*3600+1800)
628 tm1, _ := time.ParseInLocation(time.RFC3339, "2025-03-29T16:48:53+03:30", loc1)
629
630 type testData struct {
631 v Value // Input value
632 s string // Expected output string
633 }
634
635 tests := []testData{
636 // Simple types
637 {Binary{}, ""},
638 {Binary{1, 2, 3}, "010203"},
639 {Integer(123), "123"},
640 {Integer(-321), "-321"},
641 {Range{-100, 200}, "-100-200"},
642 {Range{-100, -50}, "-100--50"},
643 {Resolution{150, 300, UnitsDpi}, "150x300dpi"},
644 {Resolution{100, 200, UnitsDpcm}, "100x200dpcm"},
645 {Resolution{75, 150, 10}, "75x150unknown(0x0a)"},
646 {String("hello"), "hello"},
647 {TextWithLang{"en-US", "hello"}, "hello [en-US]"},
648 {Time{tm1}, "2025-03-29T16:48:53+03:30"},
649 {Void{}, ""},
650
651 // Collections
652 {Collection{}, "{}"},
653
654 {
655 v: Collection{
656 MakeAttr("attr1", TagInteger, Integer(1)),
657 MakeAttr("attr2", TagString, String("hello")),
658 },
659 s: "{attr1=1 attr2=hello}",
660 },
661 }
662
663 for _, test := range tests {
664 s := test.v.String()
665 if s != test.s {
666 t.Errorf("testing %s.String:\n"+
667 "value: %#v\n"+
668 "expected: %q\n"+
669 "present: %q\n",
670 reflect.TypeOf(test.v).String(),
671 test.v, test.s, s,
672 )
673 }
674 }
675}
676
677// TestValueType rests Value.Type method for various
678// kinds of the Value

Callers

nothing calls this directly

Calls 4

IntegerTypeAlias · 0.85
StringTypeAlias · 0.85
MakeAttrFunction · 0.85
StringMethod · 0.65

Tested by

no test coverage detected