Compare commits
	
		
			4 commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 0b2e178066 | |||
| a8cbfd087f | |||
| d0b6c40445 | |||
| 379819dde5 | 
					 4 changed files with 23 additions and 0 deletions
				
			
		| 
						 | 
					@ -17,6 +17,10 @@ func ParseString(in string) any {
 | 
				
			||||||
		return s
 | 
							return s
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if strings.HasPrefix(s, "!") {
 | 
				
			||||||
 | 
							return s
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	yesno := regexp.MustCompile("^(y|Y|yes|Yes|YES|n|N|no|No|NO|true|True|TRUE|false|False|FALSE|on|On|ON|off|Off|OFF)$")
 | 
						yesno := regexp.MustCompile("^(y|Y|yes|Yes|YES|n|N|no|No|NO|true|True|TRUE|false|False|FALSE|on|On|ON|off|Off|OFF)$")
 | 
				
			||||||
	yes := regexp.MustCompile("^(y|Y|yes|Yes|YES|true|True|TRUE|on|On|ON)$")
 | 
						yes := regexp.MustCompile("^(y|Y|yes|Yes|YES|true|True|TRUE|on|On|ON)$")
 | 
				
			||||||
	null := regexp.MustCompile("^(~|null|Null|NULL|none|None|NONE|nil|Nil|NIL)$")
 | 
						null := regexp.MustCompile("^(~|null|Null|NULL|none|None|NONE|nil|Nil|NIL)$")
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -38,6 +38,10 @@ func TestParse(t *testing.T) {
 | 
				
			||||||
		{"on-value", "on", true},
 | 
							{"on-value", "on", true},
 | 
				
			||||||
		{"no-value", "no", false},
 | 
							{"no-value", "no", false},
 | 
				
			||||||
		{"off-value", "off", false},
 | 
							{"off-value", "off", false},
 | 
				
			||||||
 | 
							{"skip-parsing-num", "!42", "!42"},
 | 
				
			||||||
 | 
							{"skip-parsing-bool", "!false", "!false"},
 | 
				
			||||||
 | 
							{"skip-parsing-time", "!" + when.Format(time.RFC3339), "!" + when.Format(time.RFC3339)},
 | 
				
			||||||
 | 
							{"skip-parsing-duration", "!15 mins", "!15 mins"},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, tt := range tests {
 | 
						for _, tt := range tests {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,6 +5,7 @@ import (
 | 
				
			||||||
	"encoding/json"
 | 
						"encoding/json"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"strconv"
 | 
						"strconv"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -27,6 +28,9 @@ func WriteValue(buff *bytes.Buffer, val any) (n int, err error) {
 | 
				
			||||||
			return buff.Write(o)
 | 
								return buff.Write(o)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	case string:
 | 
						case string:
 | 
				
			||||||
 | 
							if strings.HasPrefix(v, "!") {
 | 
				
			||||||
 | 
								return buff.WriteString(strings.TrimPrefix(v, "!"))
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		return buff.WriteString(v)
 | 
							return buff.WriteString(v)
 | 
				
			||||||
	case int:
 | 
						case int:
 | 
				
			||||||
		return buff.WriteString(strconv.Itoa(v))
 | 
							return buff.WriteString(strconv.Itoa(v))
 | 
				
			||||||
| 
						 | 
					@ -39,6 +43,9 @@ func WriteValue(buff *bytes.Buffer, val any) (n int, err error) {
 | 
				
			||||||
	case json.RawMessage:
 | 
						case json.RawMessage:
 | 
				
			||||||
		return buff.Write(v)
 | 
							return buff.Write(v)
 | 
				
			||||||
	case []byte:
 | 
						case []byte:
 | 
				
			||||||
 | 
							if v[0] == '!' {
 | 
				
			||||||
 | 
								return buff.Write(v[1:])
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		return buff.Write(v)
 | 
							return buff.Write(v)
 | 
				
			||||||
	case byte:
 | 
						case byte:
 | 
				
			||||||
		err = buff.WriteByte(v)
 | 
							err = buff.WriteByte(v)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -33,6 +33,14 @@ func TestWriteBuffer(t *testing.T) {
 | 
				
			||||||
		{"slice", []any{1, 2, "foo"}, `[1,2,"foo"]`, nil},
 | 
							{"slice", []any{1, 2, "foo"}, `[1,2,"foo"]`, nil},
 | 
				
			||||||
		{"map", map[string]any{"baz": 42, "foo": "bar"}, `{"baz":42,"foo":"bar"}`, nil},
 | 
							{"map", map[string]any{"baz": 42, "foo": "bar"}, `{"baz":42,"foo":"bar"}`, nil},
 | 
				
			||||||
		{"struct", struct{}{}, "", errors.New("Unsupported type struct {}")},
 | 
							{"struct", struct{}{}, "", errors.New("Unsupported type struct {}")},
 | 
				
			||||||
 | 
							{"skip-bang-num", "!42", "42", nil},
 | 
				
			||||||
 | 
							{"skip-bang-bool", "!false", "false", nil},
 | 
				
			||||||
 | 
							{"skip-bang-time", "!" + when.Format(time.RFC3339), when.Format(time.RFC3339), nil},
 | 
				
			||||||
 | 
							{"skip-bang-duration", "!15 mins", "15 mins", nil},
 | 
				
			||||||
 | 
							{"skip-bang-bytes-num", []byte("!42"), "42", nil},
 | 
				
			||||||
 | 
							{"skip-bang-bytes-bool", []byte("!false"), "false", nil},
 | 
				
			||||||
 | 
							{"skip-bang-bytes-time", []byte("!" + when.Format(time.RFC3339)), when.Format(time.RFC3339), nil},
 | 
				
			||||||
 | 
							{"skip-bang-bytes-duration", []byte("!15 mins"), "15 mins", nil},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, tt := range tests {
 | 
						for _, tt := range tests {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue