format_test.cpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * libnbt++ - A library for the Minecraft Named Binary Tag format.
  3. * Copyright (C) 2013, 2015 ljfa-ag
  4. *
  5. * This file is part of libnbt++.
  6. *
  7. * libnbt++ is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * libnbt++ is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public License
  18. * along with libnbt++. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. //#include "text/json_formatter.h"
  21. //#include "io/stream_reader.h"
  22. #include <fstream>
  23. #include <iostream>
  24. #include <limits>
  25. #include "nbt_tags.h"
  26. using namespace nbt;
  27. int main()
  28. {
  29. //TODO: Write that into a file
  30. tag_compound comp{
  31. {"byte", tag_byte(-128)},
  32. {"short", tag_short(-32768)},
  33. {"int", tag_int(-2147483648)},
  34. {"long", tag_long(-9223372036854775808U)},
  35. {"float 1", 1.618034f},
  36. {"float 2", 6.626070e-34f},
  37. {"float 3", 2.273737e+29f},
  38. {"float 4", -std::numeric_limits<float>::infinity()},
  39. {"float 5", std::numeric_limits<float>::quiet_NaN()},
  40. {"double 1", 3.141592653589793},
  41. {"double 2", 1.749899444387479e-193},
  42. {"double 3", 2.850825855152578e+175},
  43. {"double 4", -std::numeric_limits<double>::infinity()},
  44. {"double 5", std::numeric_limits<double>::quiet_NaN()},
  45. {"string 1", "Hello World! \u00E4\u00F6\u00FC\u00DF"},
  46. {"string 2", "String with\nline breaks\tand tabs"},
  47. {"byte array", tag_byte_array{12, 13, 14, 15, 16}},
  48. {"int array", tag_int_array{0x0badc0de, -0x0dedbeef, 0x1badbabe}},
  49. {"long array", tag_long_array{0x0badc0de0badc0de, -0x0dedbeef0dedbeef, 0x1badbabe1badbabe}},
  50. {"list (empty)", tag_list::of<tag_byte_array>({})},
  51. {"list (float)", tag_list{2.0f, 1.0f, 0.5f, 0.25f}},
  52. {"list (list)", tag_list::of<tag_list>({
  53. {},
  54. {4, 5, 6},
  55. {tag_compound{{"egg", "ham"}}, tag_compound{{"foo", "bar"}}}
  56. })},
  57. {"list (compound)", tag_list::of<tag_compound>({
  58. {{"created-on", 42}, {"names", tag_list{"Compound", "tag", "#0"}}},
  59. {{"created-on", 45}, {"names", tag_list{"Compound", "tag", "#1"}}}
  60. })},
  61. {"compound (empty)", tag_compound()},
  62. {"compound (nested)", tag_compound{
  63. {"key", "value"},
  64. {"key with \u00E4\u00F6\u00FC", tag_byte(-1)},
  65. {"key with\nnewline and\ttab", tag_compound{}}
  66. }},
  67. {"null", nullptr}
  68. };
  69. std::cout << "----- default operator<<:\n";
  70. std::cout << comp;
  71. std::cout << "\n-----" << std::endl;
  72. }