parser_test.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright 2016 Unknwon
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License"): you may
  4. // not use this file except in compliance with the License. You may obtain
  5. // a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  11. // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  12. // License for the specific language governing permissions and limitations
  13. // under the License.
  14. package ini_test
  15. import (
  16. "testing"
  17. . "github.com/smartystreets/goconvey/convey"
  18. "gopkg.in/ini.v1"
  19. )
  20. func TestBOM(t *testing.T) {
  21. Convey("Test handling BOM", t, func() {
  22. Convey("UTF-8-BOM", func() {
  23. f, err := ini.Load("testdata/UTF-8-BOM.ini")
  24. So(err, ShouldBeNil)
  25. So(f, ShouldNotBeNil)
  26. So(f.Section("author").Key("E-MAIL").String(), ShouldEqual, "example@email.com")
  27. })
  28. Convey("UTF-16-LE-BOM", func() {
  29. f, err := ini.Load("testdata/UTF-16-LE-BOM.ini")
  30. So(err, ShouldBeNil)
  31. So(f, ShouldNotBeNil)
  32. })
  33. Convey("UTF-16-BE-BOM", func() {
  34. })
  35. })
  36. }
  37. func TestBadLoad(t *testing.T) {
  38. Convey("Load with bad data", t, func() {
  39. Convey("Bad section name", func() {
  40. _, err := ini.Load([]byte("[]"))
  41. So(err, ShouldNotBeNil)
  42. _, err = ini.Load([]byte("["))
  43. So(err, ShouldNotBeNil)
  44. })
  45. Convey("Bad keys", func() {
  46. _, err := ini.Load([]byte(`"""name`))
  47. So(err, ShouldNotBeNil)
  48. _, err = ini.Load([]byte(`"""name"""`))
  49. So(err, ShouldNotBeNil)
  50. _, err = ini.Load([]byte(`""=1`))
  51. So(err, ShouldNotBeNil)
  52. _, err = ini.Load([]byte(`=`))
  53. So(err, ShouldNotBeNil)
  54. _, err = ini.Load([]byte(`name`))
  55. So(err, ShouldNotBeNil)
  56. })
  57. Convey("Bad values", func() {
  58. _, err := ini.Load([]byte(`name="""Unknwon`))
  59. So(err, ShouldNotBeNil)
  60. })
  61. })
  62. }