Permalink
Browse files

test/uSerial.lua - test serialization and debug

  • Loading branch information...
1 parent 6573df8 commit 8ccbd653db3d4f01fe0c094fd1d56b532b33157f @Raidar committed May 19, 2012
Showing with 433 additions and 0 deletions.
  1. +217 −0 test/uSerial.lua
  2. +107 −0 test/uSerialResult.dat
  3. +109 −0 test/uSerialSource.dat
View
@@ -0,0 +1,217 @@
+--[[ LFc testing ]]--
+
+----------------------------------------
+--[[ description:
+ -- Test: Using serialization (and debug).
+ -- Тест: Использование сериализации (и отладки).
+--]]
+--------------------------------------------------------------------------------
+local _G = _G
+
+----------------------------------------
+local context = context
+
+local tables = require 'context.utils.useTables'
+local datas = require 'context.utils.useDatas'
+local locale = require 'context.utils.useLocale'
+local serial = require 'context.utils.useSerial'
+
+local allpairs = tables.allpairs
+local addNewData = tables.extend
+
+----------------------------------------
+local log = require "context.samples.logging"
+local dbg = require "context.utils.useDebugs"
+local logShow = log.Show
+local dbgShow = dbg.Show
+--local logShow = dbgShow
+
+--------------------------------------------------------------------------------
+local unit = {}
+
+----------------------------------------
+local scriptPath = "context\\test\\"
+
+---------------------------------------- Test class
+local TTest = { -- Информация по умолчанию:
+} --- TLang
+local MTest = { __index = TTest }
+
+-- Создание объекта.
+local function CreateTest (Data) --> (object)
+ local self = {
+ Data = Data,
+ test = false,
+ } --- self
+ return setmetatable(self, MTest)
+end -- CreateTest
+
+---------------------------------------- methods
+local tconcat = table.concat
+
+-- Make data in subtable.
+function TTest:makesub (kind) --| test
+ local t, l = self.test[kind], self.test.Liter
+ l[kind] = tconcat(t) -- string with letters
+
+ -- Hash-list with positions of array items
+ for k, v in ipairs(t) do t[v] = k end
+end ---- makesub
+
+-- Fill test using source data.
+function TTest:Fill () --| Language
+
+ local l = self.test
+
+ do -- Fill .Konal
+ local t = l.Konal
+ for _, v in ipairs(l.Sonor) do t[#t + 1] = v end
+ for _, v in ipairs(l.Sinel) do t[#t + 1] = v end
+ end -- do
+
+ do -- Make data
+ self:makesub("Vocal")
+ self:makesub("Konal")
+ self:makesub("Sonor")
+ self:makesub("Sinel")
+ self:makesub("Hemil")
+ end -- do
+
+ do -- Fill .Yocal
+ local t = l.Yocal
+ local c = l.Hemal._Yocal_
+ for _, v in ipairs(l.Vocal) do t[#t + 1] = c..v end
+ end -- do
+
+ do -- Fill .Yonal
+ local t = l.Jonal
+ local c = l.Hemal._Jonal_
+ for _, v in ipairs(l.Konal) do t[#t + 1] = v..c end
+ end -- do
+end ---- Fill
+
+
+---------------------------------------- Make
+-- Загрузка.
+function TTest:Load ()
+ local Data = self.Data
+
+ self.test = datas.load(Data.SourceFile, nil, 'change')
+end ---- GenerateFormo
+
+do
+ local sortcompare = tables.sortcompare
+ local sortpairs = tables.sortpairs
+
+-- Сохранение.
+function TTest:Save ()
+ local Data = self.Data
+
+ local sortkind = {
+ --compare = sortcompare,
+ --pairs = ipairs, -- TEST: array fields
+ --pairs = tables.hpairs, -- TEST: hash fields
+ pairs = pairs, -- TEST: array + hash fields
+ --pairs = allpairs, -- TEST: all fields including from metas
+ } ---
+
+ local kind = {
+ localret = true, -- TEST: local + return instead of global
+ tnaming = true, -- TEST: temporary name of table to access fields
+ astable = true, -- TEST: serialize as one table
+ --nesting = 0, -- TEST: serialize data with max nesting level
+
+ -- TEST: for simple values:
+ --numwidth = 2, -- TEST: min number value width
+ --keyhex = 2, -- TEST: hex width for integer key
+ --valhex = 2, -- TEST: hex width for integer value
+ --valhex = true, -- TEST: hex width for integer value
+ keyfloat = true, -- TEST: using pretty float for key
+ --valfloat = true, -- TEST: using pretty float for value
+ --strlong = 80, -- TEST: long bracket strings
+
+ --pairs = allpairs, -- TEST: all pairs
+ --pairs = tables.sortpairs, -- TEST: sort pairs
+ --pargs = {},
+ --pargs = { sortkind },
+
+ -- Параметры линеаризации
+ lining = "all",
+ --lining = "array",
+ --lining = "hash",
+ --alimit = 33,
+ alimit = 60, -- TEST: length limit for line
+ --acount = 5, -- TEST: max field count on line
+ -- [[ TEST: max field count on line
+ acount = function (n, t) --> (number)
+ local l = #t
+ return l > 17 and l / 3 or l > 9 and l / 2 or l
+ end,--]]
+ awidth = 4, -- TEST: min field width on line
+--[[
+ 01..09 --> 1..9
+ 10..17 --> 5..8
+ 18..30 --> 6..10
+--]]
+
+ hlimit = 60, -- TEST: length limit for line
+ -- [[ TEST: max field count on line
+ hcount = function (n, t) --> (number)
+ local l = #t
+ return l > 14 and l / 3 or l > 5 and l / 2 or l
+ end,--]]
+ hwidth = 3, -- TEST: min field width on line
+ --hwidth = 5, -- TEST: min field width on line -- for hex
+--[[
+ 01..05 --> 1..5
+ 06..14 --> 3..7
+ 15..30 --> 5..10
+--]]
+
+ --[[ TEST: extended pretty write
+ KeyToStr = serial.KeyToText,
+ ValToStr = serial.ValToText,
+ TabToStr = serial.TabToText,
+ --]]
+ serialize = serial.prettyize,
+ } ---
+
+ --logShow(self.test, "test")
+ return datas.save(Data.ResultFile, "Data", self.test, kind)
+end ---- GenerateFormo
+
+end -- do
+
+---------------------------------------- main
+local FullNameFmt = "%s%s.%s"
+
+function unit.Execute (Data) --> (bool | nil)
+--[[ 1. Analyzing ]]
+ local Data = Data or {}
+ Data.SourceFile = Data.SourceFile or "uSerialSource.dat"
+ Data.ResultFile = Data.ResultFile or "uSerialResult.dat"
+
+--[[ 2. Configuring ]]
+ local _Test = CreateTest(Data)
+
+--[[ 3. Calling ]]
+ _Test:Load() -- Load source
+ --logShow(_Test.test, "Test")
+ _Test:Fill() -- Fill fields
+ --logShow(_Test.test, "Test")
+ _Test:Save() -- Save result
+
+ --logShow(_Test.test, "w") -- Test samples/logging
+ --dbgShow(_Test.test, "w") -- Test utils/useDebugs
+ --[[
+ -- Test "logging-to-file" object:
+ local l = dbg.open("uSerialFile.log")
+ l:data(_Test.test, "w")
+ l:close()
+ --]]
+end ---- Execute
+
+--------------------------------------------------------------------------------
+unit.Execute(nil)
+--return unit
+--------------------------------------------------------------------------------
View
@@ -0,0 +1,107 @@
+local Data
+
+Data = {
+ Formo = {},
+ Hemal = {
+ _Jonal_ = "j",
+ _Lawel_ = "w",
+ _Yocal_ = "y",
+ },
+ Hemil = {
+ "j", "y", "w",
+
+ j = 1, w = 3, y = 2,
+ Test = 1,
+ },
+ Jonal = {
+ "bj", "dj", "vj", "qj", "zj", "gj",
+ "lj", "mj", "nj", "rj", "pj", "tj",
+ "fj", "xj", "sj", "kj", "cj", "hj",
+ },
+ Konal = {
+ "b", "d", "v", "q", "z", "g",
+ "l", "m", "n", "r", "p", "t",
+ "f", "x", "s", "k", "c", "h",
+
+ b = 1, c = 17, d = 2, f = 13, g = 6, h = 18,
+ k = 16, l = 7, m = 8, n = 9, p = 11, q = 4,
+ r = 10, s = 15, t = 12, v = 3, x = 14, z = 5,
+ },
+ Liter = {
+ Hemil = "jyw",
+ Konal = "bdvqzglmnrptfxskch",
+ Sinel = "ptfxskch",
+ Sonor = "bdvqzglmnr",
+ Vocal = "aeiou",
+ },
+ Locale = "Локализация",
+ Morfo = {},
+ Order = {
+ Konal = {
+ "Sonor", "Sinel",
+ },
+ Liter = {
+ "Vocal", "Konal", "Hemil",
+ },
+ aTEST_3 = {
+ "inner table in array",
+ "Это длинная строка - в массиве. \
+С переходами на новую строку и табуляциями.\
+Очень длинная предлинная строка текста для представления строки из большого количества символов.\
+ ",
+ },
+ selfref = false, -- Data.Liter
+ },
+ Sinel = {
+ "p", "t", "f", "x", "s", "k", "c", "h",
+
+ c = 7, f = 3, h = 8, k = 6,
+ p = 1, s = 5, t = 2, x = 4,
+ },
+ Sonor = {
+ "b", "d", "v", "q", "z",
+ "g", "l", "m", "n", "r",
+
+ b = 1, d = 2, g = 6, l = 7, m = 8,
+ n = 9, q = 4, r = 10, v = 3, z = 5,
+ },
+ Vocal = {
+ "a", "e", "i", "o", "u",
+
+ a = 1, e = 2, i = 3, o = 4, u = 5,
+ },
+ Yocal = {
+ "ya", "ye", "yi", "yo", "yu",
+ },
+ aTEST = {
+ 1, 2,
+ false, -- Data.Order.aTEST_3
+ (0.56250000000000000 * 2^3),
+ {
+ "new subtable",
+
+ ["some key string"] = "some value string",
+ subsubtable = {
+ "test", "subsub",
+ },
+ },
+ 6, (0.79228162514264333 * 2^(-96)),
+
+ [0.6667] = (0.57142857142857140 * 2^(-2)),
+ nested = {
+ 1, (0.83332499999999998 * 2^2), "nest",
+ },
+ },
+ deepref = false, -- Data.Order.Konal
+ ["nil"] = 1,
+ selfref = false, -- Data.Hemal
+ ["~Test"] = 1,
+ ["Локальность"] = true,
+}
+
+Data.Order.selfref = Data.Liter
+Data.aTEST[3] = Data.Order.aTEST_3
+Data.deepref = Data.Order.Konal
+Data.selfref = Data.Hemal
+
+return Data
Oops, something went wrong.

0 comments on commit 8ccbd65

Please sign in to comment.