parser_test.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2019 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package config // import "miniflux.app/config"
  5. import (
  6. "testing"
  7. )
  8. func TestParseBoolValue(t *testing.T) {
  9. scenarios := map[string]bool{
  10. "": true,
  11. "1": true,
  12. "Yes": true,
  13. "yes": true,
  14. "True": true,
  15. "true": true,
  16. "on": true,
  17. "false": false,
  18. "off": false,
  19. "invalid": false,
  20. }
  21. for input, expected := range scenarios {
  22. result := parseBool(input, true)
  23. if result != expected {
  24. t.Errorf(`Unexpected result for %q, got %v instead of %v`, input, result, expected)
  25. }
  26. }
  27. }
  28. func TestParseStringValueWithUnsetVariable(t *testing.T) {
  29. if parseString("", "defaultValue") != "defaultValue" {
  30. t.Errorf(`Unset variables should returns the default value`)
  31. }
  32. }
  33. func TestParseStringValue(t *testing.T) {
  34. if parseString("test", "defaultValue") != "test" {
  35. t.Errorf(`Defined variables should returns the specified value`)
  36. }
  37. }
  38. func TestParseIntValueWithUnsetVariable(t *testing.T) {
  39. if parseInt("", 42) != 42 {
  40. t.Errorf(`Unset variables should returns the default value`)
  41. }
  42. }
  43. func TestParseIntValueWithInvalidInput(t *testing.T) {
  44. if parseInt("invalid integer", 42) != 42 {
  45. t.Errorf(`Invalid integer should returns the default value`)
  46. }
  47. }
  48. func TestParseIntValue(t *testing.T) {
  49. if parseInt("2018", 42) != 2018 {
  50. t.Errorf(`Defined variables should returns the specified value`)
  51. }
  52. }