foo.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. var i = require("../")
  2. , tap = require("tap")
  3. , test = tap.test
  4. , fs = require("fs")
  5. , path = require("path")
  6. , fixture = path.resolve(__dirname, "./fixtures/foo.ini")
  7. , data = fs.readFileSync(fixture, "utf8")
  8. , d
  9. , expectE = 'o = p\n'
  10. + 'a with spaces = b c\n'
  11. + '" xa n p " = "\\"\\r\\nyoyoyo\\r\\r\\n"\n'
  12. + '"[disturbing]" = hey you never know\n'
  13. + 'zr[] = deedee\n'
  14. + 'ar[] = one\n'
  15. + 'ar[] = three\n'
  16. + 'ar[] = this is included\n'
  17. + 'br = warm\n'
  18. + '\n'
  19. + '[a]\n'
  20. + 'av = a val\n'
  21. + 'e = { o: p, a: '
  22. + '{ av: a val, b: { c: { e: "this [value]" '
  23. + '} } } }\nj = "\\"{ o: \\"p\\", a: { av:'
  24. + ' \\"a val\\", b: { c: { e: \\"this [value]'
  25. + '\\" } } } }\\""\n"[]" = a square?\n'
  26. + 'cr[] = four\ncr[] = eight\n\n'
  27. +'[a.b.c]\ne = 1\n'
  28. + 'j = 2\n\n[x\\.y\\.z]\nx.y.z = xyz\n\n'
  29. + '[x\\.y\\.z.a\\.b\\.c]\na.b.c = abc\n'
  30. + 'nocomment = this\\; this is not a comment\n'
  31. , expectD =
  32. { o: 'p',
  33. 'a with spaces': 'b c',
  34. " xa n p ":'"\r\nyoyoyo\r\r\n',
  35. '[disturbing]': 'hey you never know',
  36. 'zr': ['deedee'],
  37. 'ar': ['one', 'three', 'this is included'],
  38. 'br': 'warm',
  39. a:
  40. { av: 'a val',
  41. e: '{ o: p, a: { av: a val, b: { c: { e: "this [value]" } } } }',
  42. j: '"{ o: "p", a: { av: "a val", b: { c: { e: "this [value]" } } } }"',
  43. "[]": "a square?",
  44. cr: ['four', 'eight'],
  45. b: { c: { e: '1', j: '2' } } },
  46. 'x.y.z': {
  47. 'x.y.z': 'xyz',
  48. 'a.b.c': {
  49. 'a.b.c': 'abc',
  50. 'nocomment': 'this\; this is not a comment'
  51. }
  52. }
  53. }
  54. test("decode from file", function (t) {
  55. var d = i.decode(data)
  56. t.deepEqual(d, expectD)
  57. t.end()
  58. })
  59. test("encode from data", function (t) {
  60. var e = i.encode(expectD)
  61. t.deepEqual(e, expectE)
  62. var obj = {log: { type:'file', level: {label:'debug', value:10} } }
  63. e = i.encode(obj)
  64. t.notEqual(e.slice(0, 1), '\n', 'Never a blank first line')
  65. t.notEqual(e.slice(-2), '\n\n', 'Never a blank final line')
  66. t.end()
  67. })