diff options
| author | 2026-03-10 14:44:50 +0300 | |
|---|---|---|
| committer | 2026-03-10 14:44:50 +0300 | |
| commit | 92d84f6633767830ed964ebab8c3b94c77663394 (patch) | |
| tree | 5e087e3631d46e6cb81ccf895c408a79bc154ee2 /loader_test.go | |
| parent | Полностью переписал библиотеку. Перевёл с... (diff) | |
| download | conf-1.0.0.tar.gz conf-1.0.0.tar.bz2 conf-1.0.0.tar.xz conf-1.0.0.zip | |
Diffstat (limited to '')
| -rw-r--r-- | loader_test.go | 90 |
1 files changed, 67 insertions, 23 deletions
diff --git a/loader_test.go b/loader_test.go index 3c9a84a..e2d7e48 100644 --- a/loader_test.go +++ b/loader_test.go @@ -1,41 +1,85 @@ +// Package conf_test tests. +// +// This file is part of conf library. +// Copyright (C) 2026 Alexander NeonXP Kiryukhin <i@neonxp.ru> +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. package conf_test import ( "fmt" - "log" "go.neonxp.ru/conf" ) -func ExampleLoad() { - test := ` - some directive; - group1 param1 { - group2 param2 { - group3 param3 { - key value; - } - } - } - ` - result, err := conf.Load("test", []byte(test)) +func ExampleLoadFile() { + result, err := conf.LoadFile("./example.conf") if err != nil { - log.Fatal(err) + panic("\n" + err.Error()) } - fmt.Println( + out( result.Get("group1"). - Group.Get("group2"). - Group.Get("group3"). - Group.Get("key").Value(), + Group().Get("group2"). + Group().Get("group3"). + Group().Get("key").Value(), ) // → value + out( + result.Get("group1"). + Group().Get("group2"). + Group().Get("group3"). + Group().Get("int_key").Value(), + ) // → 123 + out( + result.Get("group1"). + Group().Get("group2"). + Group().Get("group3"). + Group().Get("float_key").Value(), + ) // → 123.321 + out( + result.Get("group1"). + Group().Get("group2"). + Group().Get("group3"). + Group().Get("bool_key").Value(), + ) // → true - fmt.Println( + out( result.Get("group1"). - Group.Get("group2"). - Group.Get("group3").Value(), + Group().Get("group2"). + Group().Get("group3").Value(), ) // → param3 - // Output: value - // param3 + out( + result.Get("group1"). + Group().Get("group2"). + Group().Get("external_vars"). + StringExt(" ", func(key string) (string, bool) { + if key == "EXTERNAL_VAR" { + return "external variable", true + } + return "unknnown var", false + }), + ) // → Concatenate with external variable and integer 123 + + // Output: value (string) + // 123 (int) + // 123.321 (float64) + // true (bool) + // param3 (model.Ident) + // Concatenate with external variable and integer 123 (string) +} + +func out(a any) { + fmt.Printf("%v (%T)\n", a, a) } |
