4
0

parser_test.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package config // import "miniflux.app/v2/internal/config"
  4. import (
  5. "testing"
  6. )
  7. func TestParseBoolValue(t *testing.T) {
  8. scenarios := map[string]bool{
  9. "": true,
  10. "1": true,
  11. "Yes": true,
  12. "yes": true,
  13. "True": true,
  14. "true": true,
  15. "on": true,
  16. "false": false,
  17. "off": false,
  18. "invalid": false,
  19. }
  20. for input, expected := range scenarios {
  21. result := parseBool(input, true)
  22. if result != expected {
  23. t.Errorf(`Unexpected result for %q, got %v instead of %v`, input, result, expected)
  24. }
  25. }
  26. }
  27. func TestParseStringValueWithUnsetVariable(t *testing.T) {
  28. if parseString("", "defaultValue") != "defaultValue" {
  29. t.Errorf(`Unset variables should returns the default value`)
  30. }
  31. }
  32. func TestParseStringValue(t *testing.T) {
  33. if parseString("test", "defaultValue") != "test" {
  34. t.Errorf(`Defined variables should returns the specified value`)
  35. }
  36. }
  37. func TestParseIntValueWithUnsetVariable(t *testing.T) {
  38. if parseInt("", 42) != 42 {
  39. t.Errorf(`Unset variables should returns the default value`)
  40. }
  41. }
  42. func TestParseIntValueWithInvalidInput(t *testing.T) {
  43. if parseInt("invalid integer", 42) != 42 {
  44. t.Errorf(`Invalid integer should returns the default value`)
  45. }
  46. }
  47. func TestParseIntValue(t *testing.T) {
  48. if parseInt("2018", 42) != 2018 {
  49. t.Errorf(`Defined variables should returns the specified value`)
  50. }
  51. }