diff --git a/README.md b/README.md index 8157af38..6a757caf 100755 --- a/README.md +++ b/README.md @@ -53,6 +53,8 @@ updateLib: 2. Edite under `sstd/src/` and `test/` 3. Compile ```bash + # ./docker/alpine/build.sh # if you use alpine docker env (Only for the init) + # ./docker/alpine/run.sh # if you use alpine docker env make ``` 4. Run tests diff --git a/admis/.ash_history b/admis/.ash_history new file mode 100644 index 00000000..504d4370 --- /dev/null +++ b/admis/.ash_history @@ -0,0 +1,5 @@ +make clean +make +./exe +make clean +exit diff --git a/admis/.cache/matplotlib/fontlist-v330.json b/admis/.cache/matplotlib/fontlist-v330.json new file mode 100644 index 00000000..e4f2df38 --- /dev/null +++ b/admis/.cache/matplotlib/fontlist-v330.json @@ -0,0 +1,994 @@ +{ + "_version": 330, + "_FontManager__default_weight": "normal", + "default_size": null, + "defaultFamily": { + "ttf": "DejaVu Sans", + "afm": "Helvetica" + }, + "afmlist": [ + { + "fname": "fonts/afm/cmex10.afm", + "name": "Computer Modern", + "style": "normal", + "variant": "normal", + "weight": "medium", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/phvro8an.afm", + "name": "Helvetica", + "style": "italic", + "variant": "normal", + "weight": "medium", + "stretch": "condensed", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/ptmb8a.afm", + "name": "Times", + "style": "normal", + "variant": "normal", + "weight": "bold", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/pdfcorefonts/Courier-BoldOblique.afm", + "name": "Courier", + "style": "italic", + "variant": "normal", + "weight": "bold", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/pdfcorefonts/ZapfDingbats.afm", + "name": "ZapfDingbats", + "style": "normal", + "variant": "normal", + "weight": "medium", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/pcrro8a.afm", + "name": "Courier", + "style": "italic", + "variant": "normal", + "weight": "medium", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/ptmri8a.afm", + "name": "Times", + "style": "italic", + "variant": "normal", + "weight": "medium", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/phvr8a.afm", + "name": "Helvetica", + "style": "normal", + "variant": "normal", + "weight": "medium", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/pbkl8a.afm", + "name": "ITC Bookman", + "style": "normal", + "variant": "normal", + "weight": "light", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/pagdo8a.afm", + "name": "ITC Avant Garde Gothic", + "style": "italic", + "variant": "normal", + "weight": "demi", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/pdfcorefonts/Helvetica-Bold.afm", + "name": "Helvetica", + "style": "normal", + "variant": "normal", + "weight": "bold", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/pdfcorefonts/Times-Italic.afm", + "name": "Times", + "style": "italic", + "variant": "normal", + "weight": "medium", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/phvr8an.afm", + "name": "Helvetica", + "style": "normal", + "variant": "normal", + "weight": "medium", + "stretch": "condensed", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/pdfcorefonts/Courier-Bold.afm", + "name": "Courier", + "style": "normal", + "variant": "normal", + "weight": "bold", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/pncb8a.afm", + "name": "New Century Schoolbook", + "style": "normal", + "variant": "normal", + "weight": "bold", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/phvbo8a.afm", + "name": "Helvetica", + "style": "italic", + "variant": "normal", + "weight": "bold", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/pdfcorefonts/Times-Roman.afm", + "name": "Times", + "style": "normal", + "variant": "normal", + "weight": "roman", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/pagd8a.afm", + "name": "ITC Avant Garde Gothic", + "style": "normal", + "variant": "normal", + "weight": "demi", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/phvb8an.afm", + "name": "Helvetica", + "style": "normal", + "variant": "normal", + "weight": "bold", + "stretch": "condensed", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/cmsy10.afm", + "name": "Computer Modern", + "style": "italic", + "variant": "normal", + "weight": "medium", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/ptmr8a.afm", + "name": "Times", + "style": "normal", + "variant": "normal", + "weight": "roman", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/cmmi10.afm", + "name": "Computer Modern", + "style": "italic", + "variant": "normal", + "weight": "medium", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/psyr.afm", + "name": "Symbol", + "style": "normal", + "variant": "normal", + "weight": "medium", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/pzdr.afm", + "name": "ITC Zapf Dingbats", + "style": "normal", + "variant": "normal", + "weight": "medium", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/ptmbi8a.afm", + "name": "Times", + "style": "italic", + "variant": "normal", + "weight": "bold", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/pplr8a.afm", + "name": "Palatino", + "style": "normal", + "variant": "normal", + "weight": "roman", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/pdfcorefonts/Times-Bold.afm", + "name": "Times", + "style": "normal", + "variant": "normal", + "weight": "bold", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/phvbo8an.afm", + "name": "Helvetica", + "style": "italic", + "variant": "normal", + "weight": "bold", + "stretch": "condensed", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/pbkd8a.afm", + "name": "ITC Bookman", + "style": "normal", + "variant": "normal", + "weight": "demi", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/phvro8a.afm", + "name": "Helvetica", + "style": "italic", + "variant": "normal", + "weight": "medium", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/pagk8a.afm", + "name": "ITC Avant Garde Gothic", + "style": "normal", + "variant": "normal", + "weight": "book", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/pdfcorefonts/Times-BoldItalic.afm", + "name": "Times", + "style": "italic", + "variant": "normal", + "weight": "bold", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/pcrbo8a.afm", + "name": "Courier", + "style": "italic", + "variant": "normal", + "weight": "bold", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/pbkdi8a.afm", + "name": "ITC Bookman", + "style": "italic", + "variant": "normal", + "weight": "demi", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/putbi8a.afm", + "name": "Utopia", + "style": "italic", + "variant": "normal", + "weight": "bold", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/phvlo8a.afm", + "name": "Helvetica", + "style": "italic", + "variant": "normal", + "weight": "light", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/pcrr8a.afm", + "name": "Courier", + "style": "normal", + "variant": "normal", + "weight": "medium", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/pplri8a.afm", + "name": "Palatino", + "style": "italic", + "variant": "normal", + "weight": "medium", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/putr8a.afm", + "name": "Utopia", + "style": "normal", + "variant": "normal", + "weight": "regular", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/phvb8a.afm", + "name": "Helvetica", + "style": "normal", + "variant": "normal", + "weight": "bold", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/pdfcorefonts/Helvetica-Oblique.afm", + "name": "Helvetica", + "style": "italic", + "variant": "normal", + "weight": "medium", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/putb8a.afm", + "name": "Utopia", + "style": "normal", + "variant": "normal", + "weight": "bold", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/pplb8a.afm", + "name": "Palatino", + "style": "normal", + "variant": "normal", + "weight": "bold", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/cmr10.afm", + "name": "Computer Modern", + "style": "normal", + "variant": "normal", + "weight": "medium", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/pncbi8a.afm", + "name": "New Century Schoolbook", + "style": "italic", + "variant": "normal", + "weight": "bold", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/pdfcorefonts/Courier.afm", + "name": "Courier", + "style": "normal", + "variant": "normal", + "weight": "medium", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/pzcmi8a.afm", + "name": "ITC Zapf Chancery", + "style": "italic", + "variant": "normal", + "weight": "medium", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/pagko8a.afm", + "name": "ITC Avant Garde Gothic", + "style": "italic", + "variant": "normal", + "weight": "book", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/pdfcorefonts/Helvetica.afm", + "name": "Helvetica", + "style": "normal", + "variant": "normal", + "weight": "medium", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/putri8a.afm", + "name": "Utopia", + "style": "italic", + "variant": "normal", + "weight": "regular", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/pbkli8a.afm", + "name": "ITC Bookman", + "style": "italic", + "variant": "normal", + "weight": "light", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/pncr8a.afm", + "name": "New Century Schoolbook", + "style": "normal", + "variant": "normal", + "weight": "roman", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/phvl8a.afm", + "name": "Helvetica", + "style": "normal", + "variant": "normal", + "weight": "light", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/pcrb8a.afm", + "name": "Courier", + "style": "normal", + "variant": "normal", + "weight": "bold", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/pdfcorefonts/Courier-Oblique.afm", + "name": "Courier", + "style": "italic", + "variant": "normal", + "weight": "medium", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/pplbi8a.afm", + "name": "Palatino", + "style": "italic", + "variant": "normal", + "weight": "bold", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/pncri8a.afm", + "name": "New Century Schoolbook", + "style": "italic", + "variant": "normal", + "weight": "medium", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/pdfcorefonts/Symbol.afm", + "name": "Symbol", + "style": "normal", + "variant": "normal", + "weight": "medium", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/pdfcorefonts/Helvetica-BoldOblique.afm", + "name": "Helvetica", + "style": "italic", + "variant": "normal", + "weight": "bold", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/afm/cmtt10.afm", + "name": "Computer Modern", + "style": "normal", + "variant": "normal", + "weight": "medium", + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + } + ], + "ttflist": [ + { + "fname": "fonts/ttf/cmtt10.ttf", + "name": "cmtt10", + "style": "normal", + "variant": "normal", + "weight": 400, + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/ttf/STIXNonUniBolIta.ttf", + "name": "STIXNonUnicode", + "style": "italic", + "variant": "normal", + "weight": 700, + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/ttf/DejaVuSans-Oblique.ttf", + "name": "DejaVu Sans", + "style": "oblique", + "variant": "normal", + "weight": 400, + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/ttf/cmss10.ttf", + "name": "cmss10", + "style": "normal", + "variant": "normal", + "weight": 400, + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/ttf/STIXSizOneSymBol.ttf", + "name": "STIXSizeOneSym", + "style": "normal", + "variant": "normal", + "weight": 700, + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/ttf/cmsy10.ttf", + "name": "cmsy10", + "style": "normal", + "variant": "normal", + "weight": 400, + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/ttf/DejaVuSansMono.ttf", + "name": "DejaVu Sans Mono", + "style": "normal", + "variant": "normal", + "weight": 400, + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/ttf/DejaVuSans-Bold.ttf", + "name": "DejaVu Sans", + "style": "normal", + "variant": "normal", + "weight": 700, + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/ttf/DejaVuSans-BoldOblique.ttf", + "name": "DejaVu Sans", + "style": "oblique", + "variant": "normal", + "weight": 700, + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/ttf/DejaVuSerif.ttf", + "name": "DejaVu Serif", + "style": "normal", + "variant": "normal", + "weight": 400, + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/ttf/DejaVuSans.ttf", + "name": "DejaVu Sans", + "style": "normal", + "variant": "normal", + "weight": 400, + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/ttf/DejaVuSerif-Bold.ttf", + "name": "DejaVu Serif", + "style": "normal", + "variant": "normal", + "weight": 700, + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/ttf/STIXSizTwoSymBol.ttf", + "name": "STIXSizeTwoSym", + "style": "normal", + "variant": "normal", + "weight": 700, + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/ttf/cmr10.ttf", + "name": "cmr10", + "style": "normal", + "variant": "normal", + "weight": 400, + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/ttf/STIXSizFourSymBol.ttf", + "name": "STIXSizeFourSym", + "style": "normal", + "variant": "normal", + "weight": 700, + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/ttf/STIXGeneralItalic.ttf", + "name": "STIXGeneral", + "style": "italic", + "variant": "normal", + "weight": 400, + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/ttf/DejaVuSansMono-Oblique.ttf", + "name": "DejaVu Sans Mono", + "style": "oblique", + "variant": "normal", + "weight": 400, + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/ttf/STIXNonUniBol.ttf", + "name": "STIXNonUnicode", + "style": "normal", + "variant": "normal", + "weight": 700, + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/ttf/STIXSizFiveSymReg.ttf", + "name": "STIXSizeFiveSym", + "style": "normal", + "variant": "normal", + "weight": 400, + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/ttf/STIXSizThreeSymReg.ttf", + "name": "STIXSizeThreeSym", + "style": "normal", + "variant": "normal", + "weight": 400, + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/ttf/DejaVuSansMono-Bold.ttf", + "name": "DejaVu Sans Mono", + "style": "normal", + "variant": "normal", + "weight": 700, + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/ttf/STIXSizTwoSymReg.ttf", + "name": "STIXSizeTwoSym", + "style": "normal", + "variant": "normal", + "weight": 400, + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/ttf/cmex10.ttf", + "name": "cmex10", + "style": "normal", + "variant": "normal", + "weight": 400, + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/ttf/cmmi10.ttf", + "name": "cmmi10", + "style": "normal", + "variant": "normal", + "weight": 400, + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/ttf/STIXSizThreeSymBol.ttf", + "name": "STIXSizeThreeSym", + "style": "normal", + "variant": "normal", + "weight": 700, + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/ttf/STIXGeneralBolIta.ttf", + "name": "STIXGeneral", + "style": "italic", + "variant": "normal", + "weight": 700, + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/ttf/STIXSizOneSymReg.ttf", + "name": "STIXSizeOneSym", + "style": "normal", + "variant": "normal", + "weight": 400, + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/ttf/DejaVuSerif-BoldItalic.ttf", + "name": "DejaVu Serif", + "style": "italic", + "variant": "normal", + "weight": 700, + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/ttf/STIXNonUni.ttf", + "name": "STIXNonUnicode", + "style": "normal", + "variant": "normal", + "weight": 400, + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/ttf/DejaVuSansDisplay.ttf", + "name": "DejaVu Sans Display", + "style": "normal", + "variant": "normal", + "weight": 400, + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/ttf/STIXNonUniIta.ttf", + "name": "STIXNonUnicode", + "style": "italic", + "variant": "normal", + "weight": 400, + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/ttf/STIXSizFourSymReg.ttf", + "name": "STIXSizeFourSym", + "style": "normal", + "variant": "normal", + "weight": 400, + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/ttf/STIXGeneralBol.ttf", + "name": "STIXGeneral", + "style": "normal", + "variant": "normal", + "weight": 700, + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/ttf/DejaVuSerif-Italic.ttf", + "name": "DejaVu Serif", + "style": "italic", + "variant": "normal", + "weight": 400, + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/ttf/DejaVuSansMono-BoldOblique.ttf", + "name": "DejaVu Sans Mono", + "style": "oblique", + "variant": "normal", + "weight": 700, + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/ttf/STIXGeneral.ttf", + "name": "STIXGeneral", + "style": "normal", + "variant": "normal", + "weight": 400, + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/ttf/DejaVuSerifDisplay.ttf", + "name": "DejaVu Serif Display", + "style": "normal", + "variant": "normal", + "weight": 400, + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + }, + { + "fname": "fonts/ttf/cmb10.ttf", + "name": "cmb10", + "style": "normal", + "variant": "normal", + "weight": 400, + "stretch": "normal", + "size": "scalable", + "__class__": "FontEntry" + } + ], + "__class__": "FontManager" +} \ No newline at end of file diff --git a/run.sh b/run.sh new file mode 100755 index 00000000..7cd8df05 --- /dev/null +++ b/run.sh @@ -0,0 +1 @@ +make && ./exe diff --git a/sstd/src/definitions/typeNum.cpp b/sstd/src/definitions/typeNum.cpp index de6c09dc..008e637f 100644 --- a/sstd/src/definitions/typeNum.cpp +++ b/sstd/src/definitions/typeNum.cpp @@ -237,6 +237,9 @@ std::string sstd::typeNum2str(uchar rhs){ case sstd::num_hash_str_void_ptr: return std::string("hash_str_void_ptr" ); //case sstd::num_hash_void_ptr_void_ptr: return std::string("hash_void_ptr_void_ptr"); + case sstd::num_vec_terp_var: return std::string("vec_terp_var" ); + case sstd::num_hash_terp_var: return std::string("hash_terp_var"); + default: return std::string("err"); } diff --git a/sstd/src/definitions/typeNum.hpp b/sstd/src/definitions/typeNum.hpp index 6b369789..ca13f448 100644 --- a/sstd/src/definitions/typeNum.hpp +++ b/sstd/src/definitions/typeNum.hpp @@ -149,8 +149,11 @@ namespace sstd{ const static uchar num_mat_c_void_ptr = 115; const static uchar num_mat_r_void_ptr = 116; - const static uchar num_hash_str_void_ptr = 117; - const static uchar num_hash_void_ptr_void_ptr = 118; + const static uchar num_hash_str_void_ptr = 117; // delete later + const static uchar num_hash_void_ptr_void_ptr = 118; // delete later + + const static uchar num_vec_terp_var = 119; + const static uchar num_hash_terp_var = 120; //--- diff --git a/sstd/src/file/yaml.cpp b/sstd/src/file/yaml.cpp index a858c24a..994a8f7f 100644 --- a/sstd/src/file/yaml.cpp +++ b/sstd/src/file/yaml.cpp @@ -1,4 +1,7 @@ +#include + #include +#include #include #include @@ -8,7 +11,7 @@ #include "../definitions/typeDef.h" #include "../string/strEdit.hpp" #include "../string/strmatch.hpp" -//#include "../print/print.hpp" // for debug +#include "../print/print.hpp" // for debug //----------------------------------------------------------------------------------------------------------------------------------------------- @@ -18,12 +21,67 @@ // - sq: single quatation //----------------------------------------------------------------------------------------------------------------------------------------------- +// print + +#define sstd_print_token_base(rhs) \ + printf("\n"); \ + printf("debug info:\n"); \ + printf(" line_num_begin: %d\n", rhs.line_num_begin); \ + printf(" line_num_end: %d\n", rhs.line_num_end); \ + printf(" rawStr: `%s`\n", rhs.rawStr.c_str()); \ + printf("command:\n"); \ + printf(" type: %d\n", rhs.type); \ + printf(" format: %d\n", rhs.format); \ + printf(" list_type_cnt: %d\n", rhs.list_type_cnt); \ + printf(" hsc_lx: %d\n", rhs.hsc_lx); \ + printf(" hsc_hx: %d\n", rhs.hsc_hx); \ + printf(" hasValue: %s\n", (rhs.hasValue?"ture":"false")); \ + printf(" key_is_dqed: %s\n", (rhs.key_is_dqed?"ture":"false")); \ + printf(" key_is_sqed: %s\n", (rhs.key_is_sqed?"ture":"false")); \ + printf(" val_is_dqed: %s\n", (rhs.val_is_dqed?"ture":"false")); \ + printf(" val_is_sqed: %s\n", (rhs.val_is_sqed?"ture":"false")); \ + printf(" mult_line_val: %s\n", (rhs.mult_line_val?"ture":"false")); \ + printf(" key: `%s`\n", rhs.key.c_str()); \ + printf(" val: `%s`\n", rhs.val.c_str()); \ + printf(",\n"); + +void sstd::print(const sstd_yaml::token& rhs){ + sstd_print_token_base(rhs); + printf("\n"); +} +void sstd::for_printn(const sstd_yaml::token& rhs){ printf(" = "); sstd::print(rhs); } +void sstd::print_for_vT(const sstd_yaml::token& rhs){ + sstd_print_token_base(rhs); +} + +#undef sstd_print_token_base + +//--- + +#define sstd_print_command_v2_base(rhs) \ + printf("\n"); \ + printf("debug info:\n"); \ + printf(" line_num_begin: %d\n", rhs.line_num_begin); \ + printf(" line_num_end: %d\n", rhs.line_num_end); \ + printf(" rawStr: `%s`\n", rhs.rawStr.c_str()); \ + printf("command:\n"); \ + printf(" ope: %d\n", rhs.ope); \ + printf(" hsc: %d\n", rhs.hsc); \ + printf(" type: %d\n", rhs.type); \ + printf(" format: %d\n", rhs.format); \ + printf(" val: `%s`\n", rhs.val.c_str()); \ + printf(",\n"); + +void sstd::print(const sstd_yaml::command& rhs){ + sstd_print_command_v2_base(rhs); + printf("\n"); +} +void sstd::for_printn(const sstd_yaml::command& rhs){ printf(" = "); sstd::print(rhs); } +void sstd::print_for_vT(const sstd_yaml::command& rhs){ + sstd_print_command_v2_base(rhs); +} -#define NUM_NULL 255 -#define NUM_STR 1 -#define NUM_LIST 2 -#define NUM_HASH 3 -#define NUM_LIST_AND_HASH 4 +#undef sstd_print_command_v2_base //----------------------------------------------------------------------------------------------------------------------------------------------- @@ -67,12 +125,12 @@ std::string _extract_quotes_value(const std::string& str){ ret += " "; } }else if(new_line_cnt>=2){ -// for(uint i_t=0; i_t v = sstd::split(s, ' '); - for(uint i=0; i= 1 ); - return; -} - -//--- - -uint _head_space_or_hyphen_count(const std::string& s){ - uint c=0; - for(uint i=0; i& v, const bool ret_pipeSymbol, const bool ret_greaterThanSymbol){ + std::string ret; + if(v.size()==0){ return ret; } + + std::vector v_delimiter; + if(ret_pipeSymbol){ + // '|' + v_delimiter = std::vector(v.size()-1, std::string("\n")); + + }else if(ret_greaterThanSymbol){ + // '>' + v_delimiter = std::vector(v.size()-1, std::string(" ")); + + uint i = 0; + uint hsc = sstd::lcount(v[i], ' '); // hsc: head space count + if(hsc!=0){ v_delimiter[i] = "\n"; } + ++i; + for(; i'.\n"); } - return c; -} -bool _hsc_hx(uint& ret, const std::string& s){ - bool is_h; - if(!_is_hash(is_h, s)){ sstd::pdbg_err("quate is not closed\n"); return false; } - if(is_h){ ret = _head_space_or_hyphen_count(s); return true; - } else { ret = _head_space_count(s); return true; + // join + ret += v[0]; + for(uint i=1; i& v_cmd){ - for(uint i=0; i+123", ">-123", ">123+", ">123-". -//--- + std::string opt = sstd::lstrip(opt_in); + + ret_noSymbol=false; + ret_pipeSymbol=false; + ret_greaterThanSymbol=false; + ret_plusSymbol=false; + ret_minusSymbol=false; + ret_hasHsc=false; + ret_hsc=0; -void _data_type(uint& type, uint& num, std::string s){ - bool is_l; _is_list(is_l, num, s); - bool is_h; _is_hash(is_h, s); - - if(is_l && is_h){ type = NUM_LIST_AND_HASH; return; } - if(is_l){ type = NUM_LIST; return; } - if(is_h){ type = NUM_HASH; return; } - - type = NUM_STR; - return; -} -std::vector _get_verb(std::string s){ - std::vector v; - if(sstd::charIn('-', s)){ v.push_back("-"); } - if(sstd::charIn(':', s)){ v.push_back(":"); } - return v; -} -bool _get_value(bool& ret_val1_use_quotes, bool& ret_val2_use_quotes, std::string& ret_val1, std::string& ret_val2, std::string s, uint typeNum){ - ret_val1_use_quotes=false; - ret_val2_use_quotes=false; - ret_val1.clear(); - ret_val2.clear(); - bool dq, sq; - - switch(typeNum){ - case NUM_STR: { - ret_val1 = _extract_quotes_value(sstd::strip_quotes(sq, dq, s)); - ret_val1_use_quotes = ( dq || sq ); - } break; - case NUM_LIST: { - ret_val1 = _extract_quotes_value(sstd::strip_quotes(sq, dq, _rm_hyphen(s))); - ret_val1_use_quotes = ( dq || sq ); - } break; - case NUM_HASH: - case NUM_LIST_AND_HASH: { - std::vector v; if(!sstd::split_quotes(v, s, ':')){ sstd::pdbg_err("single quatation or double quatation is not closed\n"); return false; } - if(v.size()>=1){ ret_val1 = _extract_quotes_value(sstd::strip_quotes(sq, dq, _rm_hyphen(v[0]))); ret_val1_use_quotes = ( sq || dq ); } - if(v.size()>=2){ ret_val2 = _extract_quotes_value(sstd::strip_quotes(sq, dq, v[1] )); ret_val2_use_quotes = ( sq || dq ); } - if(v.size()>=3){ sstd::pdbg("Unexptected split by ':'."); return false; } - } break; - default: { sstd::pdbg_err("Unexpected typeNum\n"); return false; } break; + if(opt.size()==0 || (opt.size()>=1 && (opt[0]!='|' && opt[0]!='>'))){ + ret_noSymbol=true; + }else{ + for(uint i=0; i'){ if(ret_greaterThanSymbol){sstd::pdbg_err("Duplicated '>'.\n");return false;} ret_greaterThanSymbol=true; continue; } + if(opt[i]=='+'){ if(ret_plusSymbol ){sstd::pdbg_err("Duplicated '+'.\n");return false;} ret_plusSymbol =true; continue; } + if(opt[i]=='-'){ if(ret_minusSymbol ){sstd::pdbg_err("Duplicated '-'.\n");return false;} ret_minusSymbol =true; continue; } + } + std::string sNum = sstd::stripAll(opt, "|>+-"); + if(sNum.size()==0){ return true; } + if(!sstd::isNum(sNum)){ sstd::pdbg_err("Not numer.\n"); return false; } + ret_hasHsc=true; + ret_hsc = std::stoul(sNum); } return true; } -bool _get_multi_line_str(std::string& ret, const uint hsc_prev, const std::string& opt, int indent_width, const std::vector& ls, uint& i){ - std::vector v_tmp; +//--- - char separator='\n'; - //if(sstd::charIn('|', opt)){ separator = '\n'; } - if(sstd::charIn('>', opt)){ separator = ' '; } -// if(indent_width == hsc_prev){ separator = '\n'; } +bool sstd_yaml::_format_mult_line_str(std::string& ret_str, const std::string& str, const uint hsc_base_yaml, const bool has_next_token){ + std::string ret; + + std::vector v_str = sstd::splitByLine(str+"\n"); // "\n" modify the num of split sections + std::vector v_tmp; + if(v_str.size()<2){ return true; } + + bool ret_noSymbol=false, ret_pipeSymbol=false, ret_greaterThanSymbol=false; + bool ret_plusSymbol=false, ret_minusSymbol=false; + bool ret_hasHsc=false; uint ret_user_requested_hsc=0; + std::string opt=v_str[0]; + if(!_parse_mult_line_opt(ret_noSymbol, ret_pipeSymbol, ret_greaterThanSymbol, ret_plusSymbol, ret_minusSymbol, ret_hasHsc, ret_user_requested_hsc, opt)){ sstd::pdbg_err("_parse_mult_line_opt() is failed.\n"); return false; } - for(; i=0 && s.size()>0){ - uint hsc = _head_space_count(s); - - if(hsc+1 <= (hsc_prev + indent_width)){ sstd::pdbg_err("indent indecation is too large.\n"); return false; } + if(ret_noSymbol){ + // noSymbol - if(hsc_prev + indent_width == hsc){ // for "- >[Num]", "- >[Num]" - s = sstd::strip(s); + // parse multi-line string to YAML style string + std::string tmp; + bool prev_is_line_break=true; + for(uint i=0; i `["ab"]`. + ret.pop_back(); + ret += tmp; + prev_is_line_break=false; }else{ - s = sstd::rstrip(s); - if(indent_width < (int)s.size()){ - separator = '\n'; - s = &s[hsc_prev+indent_width]; - } + ret += ' ' + tmp; + prev_is_line_break=false; } - }else{ - s = sstd::strip(s); } - v_tmp.push_back(s); - }else{ - --i; - break; } - } - - if (opt=="|" || opt==">" ){ - sstd::rmEmpty_r_ow(v_tmp); - ret = sstd::join(v_tmp, separator); - ret += "\n"; - }else if(opt=="|-" || opt==">-"){ - sstd::rmEmpty_r_ow(v_tmp); - ret = sstd::join(v_tmp, separator); - }else if(opt=="|+" || opt==">+"){ - uint cnt = sstd::cntEmpty_r(v_tmp) + 1; - sstd::rmEmpty_r_ow(v_tmp); - ret = sstd::join(v_tmp, separator) + std::string(cnt, '\n'); + sstd::rstripAll_ow(ret, " \n"); + }else{ - sstd::pdbg_err("Unexpected case\n"); return false; - } + // "|+N", "|-N", ">+N" or ">-N" + + const uint hsc_base_1st_line=sstd::lcount(v_str[1], ' '); // hsc: head space count + if(hsc_base_1st_line<=hsc_base_yaml){ + // Error case. + // - | + // a <- error (Required more than 1 hsc) + sstd::pdbg_err("The space count of multiple line indent is invalid.\n"); + return false; + } - return true; -} -bool _check_val_and_overwrite_multi_line_str(std::string& val_rw, const uint hsc_prev, const std::vector& ls, uint& i){ - int indent_width = -1; + uint hsc_base=hsc_base_1st_line; + if(ret_hasHsc){ + if(ret_user_requested_hsc==0){ sstd::pdbg_err("The user requested indent can not be 0.\n"); return false; } + if(ret_user_requested_hsc>hsc_base_1st_line){ + // Error case. + // - |9 + // a <- error (Required more than 10 hsc) + sstd::pdbg_err("The user requested indent size is too large.\n"); + return false; + } + hsc_base=hsc_base_yaml+ret_user_requested_hsc; + } + + for(uint i=1; i-") || // case: "- |-123", "- >-123", "hash-key: |-123" or "hash-key: >-123" - val_rw.starts_with("|+") || val_rw.starts_with(">+") ){ // case: "- |+123", "- >+123", "hash-key: |+123" or "hash-key: >+123" - ++i; - std::string opt; opt += val_rw[0]; opt += val_rw[1]; - if(val_rw.size()>=3){ - indent_width = std::stoi(&val_rw[2]); - }else{ - indent_width = _head_space_count(ls[i]); + if(have_str_except_space && hsc=hsc_base){ + tmp += (char*)&v_str[i][hsc_base]; + } + + v_tmp.push_back(tmp); } + + if((!ret_plusSymbol) && (!ret_minusSymbol)){ + // "|N" or ">N" - if(!_get_multi_line_str(val_rw, hsc_prev, opt, indent_width, ls, i)){ return false; } + int cnt = (int)sstd::cntEmpty_r(v_tmp); + sstd::rmEmpty_r_ow(v_tmp); + ret = _join_mult_line(v_tmp, ret_pipeSymbol, ret_greaterThanSymbol) + std::string(std::min(1,cnt), '\n'); + + }else if(ret_minusSymbol){ + // "|-N" or ">-N" + + sstd::rmEmpty_r_ow(v_tmp); + ret = _join_mult_line(v_tmp, ret_pipeSymbol, ret_greaterThanSymbol); + + }else if(ret_plusSymbol){ + // "|+N" or ">+N" + + int cnt = (int)sstd::cntEmpty_r(v_tmp) + (int)(has_next_token?1:0); + sstd::rmEmpty_r_ow(v_tmp); + ret = _join_mult_line(v_tmp, ret_pipeSymbol, ret_greaterThanSymbol) + std::string(cnt, '\n'); - }else if(val_rw.starts_with("|" ) || val_rw.starts_with(">" )){ // case: "- |123", "- >123", "hash-key: |123" or "hash-key: >123" - ++i; - std::string opt; opt += val_rw[0]; - if(val_rw.size()>=2){ - indent_width = std::stoi(&val_rw[1]); }else{ - indent_width = _head_space_count(ls[i]); + sstd::pdbg_err("Unexpected case\n"); return false; } - - if(!_get_multi_line_str(val_rw, hsc_prev, opt, indent_width, ls, i)){ return false; } } + std::swap(ret_str, ret); return true; } -bool _parse_yaml(std::vector& ret_vCmd, const std::vector& ls, const uint base_idx){ +bool sstd_yaml::_token2cmd(std::vector& ret_vCmd, const std::vector& v_token){ - for(uint i=0; i │ >= │ >= │ + // │ s │ │ │ │ │ + // │ c ├───────────────────┼───────────────────┼───────────────────┼───────────────────┤ + // │ _ │ list_and_hash │ > │ >= │ >= │ + // │ n │ (works as a list) │ │ │ │ + // │ e ├───────────────────┼───────────────────┼───────────────────┼───────────────────┤ + // │ x │ hash │ > │ > │ > │ + // │ t │ │ │ │ │ + // └───┴───────────────────┴───────────────────┴───────────────────┴───────────────────┘ + // + bool isGr = t.type==sstd_yaml::num_list || t_nx.type==sstd_yaml::num_hash; // check '>' case + bool isGrOrEq = !isGr; // check '>=' case + if((isGr && hsc_next> hsc_curr) || + (isGrOrEq && hsc_next>=hsc_curr) ) + { + // --- debug info --- + c.line_num_begin = t.line_num_begin; + c.line_num_end = t.line_num_end; + c.rawStr = t.rawStr; + // --- construct info --- + c.ope = sstd_yaml::ope_stack; + c.hsc = hsc_next; + + ret_vCmd.push_back(c); + } + } } return true; } -bool _construct_var(sstd::terp::var& ret_yml, const std::vector& v_cmd){ - std::vector v_dst; - std::vector v_hsc_lx; // v: vector, hsc: head space count, _lx: list-index. - std::vector v_hsc_hx; // v: vector, hsc: head space count. _hx: hash-index. - v_dst.push_back(ret_yml.p()); - v_hsc_lx.push_back(0); - v_hsc_hx.push_back(0); + +bool _is_control_chars(const char c){ + return (c=='[' || c==']' || c=='{' || c=='}' || c==':' || c==','); +} +bool sstd_yaml::_split_quotes_by_control_chars(std::vector& ret, const char* str, const uint str_len){ + bool is_escaped=false; + bool in_d_quate=false; // double quate + bool in_s_quate=false; // single quate + std::string buf; + uint i=0; + while(i=str_len){break;} } + + if(!is_escaped && !in_s_quate && str[i]=='"' ){ in_d_quate = !in_d_quate; } + if(!is_escaped && !in_d_quate && str[i]=='\''){ in_s_quate = !in_s_quate; } + + if(!in_d_quate && !in_s_quate && (_is_control_chars(str[i]))){ + buf = sstd::strip(buf); + if(buf.size()!=0){ + ret.push_back(buf); + buf.clear(); + } + ret.push_back(std::string(1, str[i])); // append a control char + ++i; + }else{ + buf += str[i]; + ++i; + } + + is_escaped=false; + } + if(in_d_quate){ ret.clear(); return false; } + if(in_s_quate){ ret.clear(); return false; } + buf = sstd::strip(buf); + if(buf.size()!=0){ ret.push_back(buf); } + + return true; +} +bool _get_hash_value(bool& is_null, std::string& ret_value, const std::vector& v_cs, uint& i){ + + if(i+3 v_cs; // vector of commands and string + if(!sstd_yaml::_split_quotes_by_control_chars(v_cs, s_in.c_str(), s_in.size())){ sstd::pdbg_err("_split_quotes_by_control_chars() is failed. Un-cloused quate.\n"); return false; } + + std::vector v_dst; + v_dst.push_back( &var_out ); + + for(uint i=0; i& v_cmd){ + std::vector v_dst; // v: vector, _dst: destination. An address stack for sstd_yaml::ope_alloc (follows the YAML indent) + std::vector v_dst_cr; // v: vector, _dst: destination address, _cr: current. An address stack for sstd_yaml::ope_stack or sstd_yaml::ope_assign. + std::vector v_hsc; // v: vector, hsc: head space count + v_dst.push_back(&ret_yml); + v_dst_cr.push_back(&ret_yml); + v_hsc.push_back(0); for(uint i=0; i hsc_base_lx){ - v_hsc_lx.push_back(v_cmd[i].hsc_lx); - --i; - continue; - }else if(v_cmd[i].hsc_lx < hsc_base_lx){ - v_dst.pop_back(); - v_hsc_lx.pop_back(); - --i; - continue; +//----------------------------------------------------------------------------------------------------------------------------------------------- +// str2token section + +bool _is_flow(const std::string& subt){ + return (subt.starts_with('[') || subt.starts_with('{')); +} +bool _is_end_marker(const std::string& subt){ + return subt.starts_with("..."); +} +bool _is_separator(const std::string& subt){ + return subt.starts_with("---"); +} + +bool sstd_yaml::_str2token_except_multilines(std::vector& ret, const std::string& str){ + // Parse rule of YAML string + // + // Rule1. For default, Block-Style-String ("- ", ": ") and Line-Break-Codes ('\n') are + // treated as controle-charactors ("- ", ": ", '\n'). + // String are splitted by the controle-characotrs + // if the target string is out of quates ("", '') and brackets ([], {}) ranges. + // / デフォルトでは,Block-Style の文字列 ("- ", ": ") と改行コード ('\n') を制御文字列として扱います. + // 引用符 ("", '') と括弧 ([], {}) の範囲外では,文字列は制御文字列で分割されます. + // + // Rule2. Skipping the splitting process using controle-charactors ("- ", ": ", '\n') + // if the string in quates range. + // / 文字列がクォーテーションで括られている場合は, + // 制御文字 ("- ", ": ", '\n') での文字列の分割を停止します. + // + // Rule3. Skipping the splitting process using controle-charactors ("- ", ": ", '\n') + // after detecting the subtoken is beginning from the beginning of brackets ([, {) for flow-style-notation. + // / Subtoken が Flow-Style 表記の開始を示す括弧 ([, {) で開始される場合は, + // 制御文字 ("- ", ": ", '\n') での文字列の分割を停止します. + // + // Rule4. Detecting comments by "#" (in head of the line) or " #" notation + // / コメントは "#" (行の先頭) または " #" 表記で判定します + // + // Rule5. Using line break code ('\n') as a control charactor + // excepting the case of subtoken begin from multi-line notation charactor ('|'). + // / 改行コード ('\n') は,制御文字として扱います. + // ただし,subtoken がマルチライン表記を示す文字 ('|') から始まる場合を除きます. + + uint line_num = 1; // line number is 1 indexed + + // for quotes ("", '') + bool is_escaped=false; // \", \' + bool in_d_quate=false; // double quate ("") + bool in_s_quate=false; // single quate ('') + + for(uint r=0; str[r]!='\0';){ // r: read place + sstd_yaml::token tmp; + tmp.line_num_begin = line_num; + + std::string subt; // subtoken + + // for hsc + bool is_hs=true; // To identify the spacs ' ' is hsc or charactor between the token. + + // for type + bool is_list=false; // is list type "- " + bool is_hash=false; // is hash type "k: v" + bool is_flow=false; // is flow style "[{k: v}]" + bool is_end_marker=false; // is "..." + bool subt_has_a_val=false; // for "- a - b - c -" + + int num_of_square_brackets=0; // [] + int num_of_curly_brackets=0; // {} + + // for quates ("", '') + bool dqed=false; // double quated + bool sqed=false; // single quated + + for(;;++r){ + if(str[r]=='\\'){ is_escaped=true; tmp.rawStr+=str[r]; subt+=str[r]; ++r; } // Escape for inside quates will be processed at xxx() functiuon. + if(str[r]=='\0'){ ++line_num; break; } + if(str[r]!=' '){ is_hs=false; } + if(str[r]==' ' && is_hs){ ++tmp.hsc_lx; ++tmp.hsc_hx; } + + if(!is_escaped && !in_s_quate && str[r]=='"' ){ in_d_quate = !in_d_quate; dqed=true; } + if(!is_escaped && !in_d_quate && str[r]=='\''){ in_s_quate = !in_s_quate; sqed=true; } + + if(!in_d_quate && !in_s_quate){ + if((subt.size()==0 && str[r]=='#') || (str[r]==' ' && str[r+1]=='#')){ + tmp.rawStr+=str[r]; ++r; + while(str[r]!='\0' && str[r]!='\n'){ tmp.rawStr+=str[r]; ++r; } // skip comments + if(str[r]=='\0'){ ++line_num; break; } + } + + is_end_marker = _is_end_marker(subt); + if(is_end_marker){ break; } + + is_flow = _is_flow(subt+str[r]); + if(!is_flow){ + // Block Style + + // for Unix + if(str[r]=='-' && str[r+1]=='\n' && !subt_has_a_val){ subt.clear(); is_list=true; ++tmp.list_type_cnt; tmp.rawStr+=str[r]; continue; } + if(str[r]==':' && str[r+1]=='\n' ){ tmp.key=std::move(sstd::strip(subt)); subt.clear(); is_hash=true; tmp.rawStr+=str[r]; tmp.key_is_dqed=dqed; tmp.key_is_sqed=sqed; continue; } + + // the other case + if(str[r]=='-' && str[r+1]==' ' && !subt_has_a_val){ subt.clear(); is_list=true; ++tmp.list_type_cnt; tmp.rawStr+=str[r]; ++r; tmp.rawStr+=str[r]; continue; } + if(str[r]==':' && str[r+1]==' ' ){ tmp.key=std::move(sstd::strip(subt)); subt.clear(); is_hash=true; tmp.rawStr+=str[r]; tmp.key_is_dqed=dqed; tmp.key_is_sqed=sqed; ++r; tmp.rawStr+=str[r]; continue; } + }else{ + // Flow Style + if(str[r]=='['){ ++num_of_square_brackets; } + if(str[r]==']'){ --num_of_square_brackets; } + if(str[r]=='{'){ ++num_of_curly_brackets; } + if(str[r]=='}'){ --num_of_curly_brackets; } + } } - } break; - case sstd::num_hash_str_void_ptr: { - // hash - if(v_cmd[i].hsc_hx > hsc_base_hx){ - v_hsc_hx.push_back(v_cmd[i].hsc_hx); - --i; - continue; - }else if(v_cmd[i].hsc_hx < hsc_base_hx){ - v_dst.pop_back(); - v_hsc_hx.pop_back(); - --i; - continue; - }else if(v_cmd[i].verb=='x'){ - v_dst.pop_back(); - v_hsc_hx.pop_back(); - --i; - continue; + + // Checking the line break + if(str[r]=='\n'){ // Uinx ("\n") + ++line_num; + is_hs=true; + if(!is_flow && !is_escaped && !in_d_quate){ ++r; break; } + if( is_flow && num_of_square_brackets==0 && num_of_curly_brackets==0){ ++r; break; } } - } break; - case sstd::num_null: {} break; - default: { sstd::pdbg_err("Unexpected data type\n"); } break; + + // save the input string to the buffers + tmp.rawStr += str[r]; + subt += str[r]; + if(str[r]!='-' && str[r]!=' '){ subt_has_a_val=true; } + + // init + is_escaped = false; + } + if(is_end_marker){ break; } + tmp.line_num_end = std::max((int)tmp.line_num_begin, ((int)line_num)-1); + + tmp.val=std::move(sstd::strip(subt)); + tmp.val_is_dqed=dqed; + tmp.val_is_sqed=sqed; + + if(is_list){ tmp.type += sstd_yaml::num_list; tmp.hsc_hx+=2; } + if(is_hash){ tmp.type += sstd_yaml::num_hash; } + if(is_flow){ tmp.format = sstd_yaml::num_flow_style_base; } + + // Skip empty tokens until the first non-empty token occurs. (Empty token is treated as a line-break related with to other token in a context of multi-line YAML) + if(ret.size()==0 && + tmp.key.size()==0 && + tmp.val.size()==0 && + tmp.type==sstd_yaml::num_str){ continue; } + + // set hasValue + tmp.hasValue=false; + switch(tmp.type){ + case sstd_yaml::num_str: { if(tmp.val_is_dqed||tmp.val_is_sqed||tmp.val.size()>=1){tmp.hasValue=true;} } break; + case sstd_yaml::num_list: { if(tmp.val_is_dqed||tmp.val_is_sqed||tmp.val.size()>=1){tmp.hasValue=true;} } break; // check the value is NOT NULL + case sstd_yaml::num_list_and_hash: + case sstd_yaml::num_hash: { if(tmp.val_is_dqed||tmp.val_is_sqed||tmp.val.size()>=1){tmp.hasValue=true;} } break; // check the value is NOT NULL + default: { sstd::pdbg_err("Unexpected data type\n"); return false; } break; } - // set dst and value - switch(v_cmd[i].verb){ - case 's': { // 's': string - if(var.typeNum()!=sstd::num_null){ sstd::pdbg_err("OverWritting the existing data. (String data type can only take one data.)\n"); break; } - var = v_cmd[i].val1.c_str(); - } break; - case '-': { // '-': list - if(v_cmd[i].val1.size()>=1 || v_cmd[i].val1_use_quotes){ // 'val1_use_quotes' is required to detect 0 length string - var.push_back( v_cmd[i].val1.c_str() ); - }else{ - var.push_back( sstd::terp::list() ); - v_dst.push_back( var[var.size()-1].p() ); + ret.push_back(std::move(tmp)); + } + if(in_d_quate){ ret.clear(); sstd::pdbg_err("The variable check of `in_d_quate` failed.\n"); return false; } + if(in_s_quate){ ret.clear(); sstd::pdbg_err("The variable check of `in_s_quate` failed.\n"); return false; } + + if(str.size()>=1 && str[str.size()-1]=='\n'){ + ret.push_back(sstd_yaml::token()); + } + + return true; +} +bool _is_all_the_data_str_type(const std::vector& v){ + for(uint i=0; i& v){ + for(uint i=0; i& ret, const std::vector& v){ + if(v.size()==0){ return true; } + + sstd_yaml::token t = v[0]; + //t.line_num_begin = v[ 0 ].line_num_begin; + t.line_num_end = v[v.size()-1].line_num_end; + + for(uint i=1; i& io){ + std::vector ret; + + for(uint i=0; i=1 || v_cmd[i].val2_use_quotes){ // 'val2_use_quotes' is required to detect 0 length string - var[ v_cmd[i].val1.c_str() ] = v_cmd[i].val2.c_str(); - }else{ - v_dst.push_back( var[v_cmd[i].val1.c_str()].p() ); + + // For `ti == t.list_type_cnt`. + { + sstd_yaml::token tmp = t; + + tmp.list_type_cnt = 1; + tmp.hsc_lx = tmp.hsc_lx + 2 * ti; + tmp.hsc_hx = tmp.hsc_lx + 2; + + ret.push_back(std::move(tmp)); } - } break; - default: { sstd::pdbg_err("ERROR\n"); } break; } + } + + std::swap(ret, io); + return true; +} +bool sstd_yaml::_token2token_merge_multilines(std::vector& io){ + std::vector ret; + + bool is_all_the_data_flowStyle = _is_all_the_data_flowStyle(io); + if(is_all_the_data_flowStyle){ + + // Do notheing for the flowStyle + + return true; + } + bool is_all_the_data_str_type = _is_all_the_data_str_type(io); + if(is_all_the_data_str_type){ + + if(!_merge_all_str(ret, io)){ sstd::pdbg_err("_merge_all_str() was failed.\n"); return false; } + + std::swap(ret, io); + return true; + } + + // mearge all the separated multi-line tokens + uint i=0; + do{ + sstd_yaml::token* pT = &io[i]; + sstd_yaml::token tmp = (*pT); - //sstd::printn(var); // for debug - //sstd::printn(ret_yml); // for debug + // Check criteria values (Defining criteria value as a base token like list, hash or list_and_hash type to merge) + bool start_with_string = (*pT).val.size()>=1; + uint criteria_hsc = _get_criteria_hsc((*pT)); + + for(uint merge_cnt=1;; ++merge_cnt){ + // Update + ++i; + if( i>=io.size() ){ break; } + pT = &io[i]; + + bool is_control_types = _is_control_types((*pT).type); + + // Check break + uint curr_hsc = _get_current_hsc((*pT)); + if( merge_cnt==1 && is_control_types && (!start_with_string||(curr_hsc<=criteria_hsc)) ){ break; } + // - `!start_with_string` is for: + // │ k0: + // │ k1: v + // - `curr_hsc<=criteria_hsc` is for: + // │ - k1: v1 + // │ - k2: v2 + + // Update `start_with_string` to the current token + start_with_string |= (*pT).type==sstd_yaml::num_str; // for "k:\n l1\n l2" + // Check the needs of breaking the merge process + // Under the following situation, the parser needs to break the process of multi-line merging. + // - `start_with_string`: The string start with non-control charactor + // - `(*pT).key.size()!=0||(*pT).val.size()!=0`: The line is NOT Empty. (If the line is empty, the parser needs to treat as a line break of multi-line string). + // - `curr_hsc<=criteria_hsc`: The line is out of scope. + if( start_with_string && (((*pT).key.size()!=0||(*pT).val.size()!=0||(*pT).key_is_dqed||(*pT).key_is_sqed||(*pT).val_is_dqed||(*pT).val_is_sqed) && curr_hsc<=criteria_hsc) ){ break; } + + if( _is_separator((*pT).rawStr) ){ break; } + + // Copy values + tmp.rawStr += '\n' + (*pT).rawStr; + tmp.val += '\n' + (*pT).rawStr; // Needs to copy as row string in order to treat multi-line string as a raw data. Ex1: "k:\n x\n - a" is interpreted as `{k: "x - a"}`. Ex2: "k: |\n x # comment" is interpreted as `{k: "x # comment"}`. + tmp.line_num_end = (*pT).line_num_end; + tmp.mult_line_val = true; + } + + ret.push_back(std::move(tmp)); + }while( i& io){ + + for(uint i=0; i(i+1)); + if(!sstd_yaml::_format_mult_line_str(t.val, t.val, hsc_base_yaml, has_next_token)){ sstd::pdbg_err("sstd_yaml::_format_mult_line_str() is failed.\n"); return false; } + if(!has_next_token){ sstd::rstripAll_ow(t.rawStr, " \n"); } + } + if(is_key_quated){ + bool key_sq, key_dq; + t.key = sstd::strip_quotes(key_sq, key_dq, t.key); + } + if(is_val_quated){ + bool val_sq, val_dq; + t.val = sstd::strip_quotes(val_sq, val_dq, t.val); + } + } + + return true; +} +bool sstd_yaml::_str2token(std::vector& ret, const char* str_in){ + std::string str = std::regex_replace(str_in, std::regex("\r"), ""); // "\r\n" -> "\n" + + if(!sstd_yaml::_str2token_except_multilines(ret, str.c_str())){ sstd::pdbg_err("sstd_yaml::_str2token_except_multilines() was failed.\n"); return false; } + if(!sstd_yaml::_token2token_split_bv_list_type_cnt(ret)){ sstd::pdbg_err("sstd_yaml::_token2token_split_bv_list_type_cnt() was failed.\n"); return false; } + if(!sstd_yaml::_token2token_merge_multilines(ret)){ sstd::pdbg_err("sstd_yaml::_token2token_merge_multilines() was failed.\n"); return false; } + if(!sstd_yaml::_token2token_postprocess(ret)){ sstd::pdbg_err("sstd_yaml::_token2token_postprocess() was failed.\n"); return false; } return true; } +bool sstd_yaml::_str2token(std::vector& ret, const std::string& str){ return sstd_yaml::_str2token(ret, str.c_str()); } -//--- +//----------------------------------------------------------------------------------------------------------------------------------------------- +// YAML load section -bool sstd::yaml_load(sstd::terp::var& ret_yml, const char* s){ - bool tf = true; +bool _yaml_load_base(sstd::terp::var& ret_yml, const std::vector& v_token){ + + std::vector v_cmd; + if(!sstd_yaml::_token2cmd(v_cmd, v_token)){ return false; } - std::vector ls; if(! sstd::splitByLine_quotes(ls, s)){ sstd::pdbg_err("single or double quatation is not closed\n"); return false; } // v: vector, ls: line string - //sstd::printn(ls); - std::vector v_cmd; if(!_parse_yaml(v_cmd, ls, 0)){ return false; } - //_print(v_cmd); if(!_construct_var(ret_yml, v_cmd)){ return false; } - return tf; + return true; +} +bool sstd::yaml_load(sstd::terp::var& ret_yml, const char* s){ + + std::vector v_token; + if(!sstd_yaml::_str2token(v_token, s)){ sstd::pdbg_err("single or double quatation is not closed\n"); return false; } // v: vector, ls: line string + + if(!_yaml_load_base(ret_yml, v_token)){ sstd::pdbg_err("_yaml_load_base() is failed.\n"); return false; } + + return true; } bool sstd::yaml_load(sstd::terp::var& ret_yml, const std::string& s){ return sstd::yaml_load(ret_yml, s.c_str()); } @@ -571,25 +1214,43 @@ std::vector> _split_by_separator(const std::vector> _split_by_separator(std::vector& vT){ + std::vector> ret_vvT; + + std::vector tmp_vT; + for(uint i=0; i& ret_vYml, const char* s){ - std::vector ls; if(!sstd::splitByLine_quotes(ls, s)){ sstd::pdbg_err("double quatation is not closed\n"); return false; } // v: vector, ls: line string - std::vector> v_ls = _split_by_separator(ls); - + std::vector v_token; + if(!sstd_yaml::_str2token(v_token, s)){ sstd::pdbg_err("single or double quatation is not closed\n"); return false; } // v: vector, ls: line string + + std::vector> vvT = _split_by_separator(v_token); + uint base_idx=0; - for(uint i=0; i v_cmd; if(!_parse_yaml(v_cmd, v_ls[i], base_idx)){ return false; } - if(!_construct_var(ret_yml, v_cmd)){ return false; } - + if(!_yaml_load_base(ret_yml, vvT[i])){ sstd::pdbg_err("_yaml_load_base() is failed.\n"); return false; } ret_vYml.push_back(std::move(ret_yml)); - base_idx += v_ls[i].size() + 1; + + base_idx += 1 + vvT[i].size(); } return true; } bool sstd::yaml_load_all(std::vector& ret_vYml, const std::string& s){ return sstd::yaml_load_all(ret_vYml, s.c_str()); } -//----------------------------------------------------------------------------------------------------------------------------------------------- +//--- bool sstd::yaml_load(sstd::terp::var& ret_yml, sstd::file& fp){ size_t size = fp.fsize(); @@ -598,7 +1259,6 @@ bool sstd::yaml_load(sstd::terp::var& ret_yml, sstd::file& fp){ sstd::pdbg_err("fread was failed.\n"); return false; } - //printf("&raw[0] = %s\n", &raw[0]); if(!sstd::yaml_load(ret_yml, (const char*)&raw[0])){ return false; } @@ -611,7 +1271,6 @@ bool sstd::yaml_load_all(std::vector& ret_vYml, sstd::file& fp) sstd::pdbg_err("fread was failed.\n"); return false; } - //printf("&raw[0] = %s\n", &raw[0]); if(!sstd::yaml_load_all(ret_vYml, (const char*)&raw[0])){ return false; } diff --git a/sstd/src/file/yaml.hpp b/sstd/src/file/yaml.hpp index 93923a44..28b546d2 100644 --- a/sstd/src/file/yaml.hpp +++ b/sstd/src/file/yaml.hpp @@ -6,9 +6,110 @@ #include "../memory/terp/terp.hpp" #include "../memory/terp/print.hpp" // for debug +//----------------------------------------------------------------------------------------------------------------------------------------------- +// internal functions for unit test + +namespace sstd_yaml{ + + //--- + // operation definition + + const static uint8 ope_null = 255; + const static uint8 ope_alloc = 0; // allocate + const static uint8 ope_stack = 1; // stacking a value to v_dst + const static uint8 ope_assign = 2; // assignemnt + + //--- + // type definition + + // TODO: num_ -> type_ に名前を置換する + + const static uint8 num_null = 255; + const static uint8 num_block_style_base = 0; + const static uint8 num_str = 0; // for BLOCK_STYLE + const static uint8 num_list = 1; // for BLOCK_STYLE + const static uint8 num_hash = 2; // for BLOCK_STYLE + const static uint8 num_list_and_hash = 3; // for BLOCK_STYLE + const static uint8 num_flow_style_base = 4; + // sstd_yaml::num_flow_style_base + sstd_yaml::num_str 4 // reserved number for FLOW_STYLE + // sstd_yaml::num_flow_style_base + sstd_yaml::num_list 5 // reserved number for FLOW_STYLE + // sstd_yaml::num_flow_style_base + sstd_yaml::num_hash 6 // reserved number for FLOW_STYLE + // sstd_yaml::num_flow_style_base + sstd_yaml::num_list_and_hash 7 // reserved number for FLOW_STYLE + + //--- + // token for proceed YAML parsing + + struct token { + // Data for Debug YAML parsing + uint line_num_begin = 1; // beginning line number + uint line_num_end = 1; // endding line number (for multipleline) + std::string rawStr; // A raw string splitted by line concering the YAML processing units. + + // Data structure to load YAML + //uint type = sstd_yaml::num_null; // sstd_yaml::num_str; // A destination type number of this line + uint type = sstd_yaml::num_str; // A destination type number of this line + uint format = sstd_yaml::num_block_style_base; // If containing flow style notation + uint list_type_cnt = 0; // Number of list type. (`- - - v`) + uint hsc_lx = 0; // head space counts for list type + uint hsc_hx = 0; // head space counts for hash type + + bool hasValue = false; // If the value (val1 or val2) is vaild for each data type (list or hash). + bool key_is_dqed = false; + bool key_is_sqed = false; + bool val_is_dqed = false; + bool val_is_sqed = false; + bool mult_line_val = false; + std::string key; // key for "hash" + std::string val; // value for "list" or "hash" + }; + struct command{ + // Data for Debug YAML parsing + uint line_num_begin = 1; // beginning line number + uint line_num_end = 1; // endding line number (for multipleline) + std::string rawStr; // A raw string splitted by line concering the YAML processing units. + + // Data structure to construct YAML + uint ope; // operation + uint hsc; // hsc: head space count + uint8 type; // data type + uint8 format; // data format + std::string val; // value + }; + + //--- + + bool _split_quotes_by_control_chars(std::vector& ret, const char* str, const uint str_len); + + //--- + + bool _format_mult_line_str(std::string& ret, const std::string& str, const uint hsc_base_yaml, const bool has_next_token); + + //--- + + bool _str2token_except_multilines(std::vector& ret, const std::string& str); + bool _token2token_split_bv_list_type_cnt(std::vector& io); + bool _token2token_merge_multilines(std::vector& io); + bool _token2token_postprocess(std::vector& io); + bool _str2token(std::vector& ret, const char* str); + bool _str2token(std::vector& ret, const std::string& str); + + bool _token2cmd(std::vector& ret_vCmd, const std::vector& v_token); + bool _token2json(std::string& s_json, const std::vector& v_token); + + //--- +} + //----------------------------------------------------------------------------------------------------------------------------------------------- namespace sstd{ + void print(const sstd_yaml::token& rhs); + void for_printn(const sstd_yaml::token& rhs); + void print_for_vT(const sstd_yaml::token& rhs); + + void print(const sstd_yaml::command& rhs); + void for_printn(const sstd_yaml::command& rhs); + void print_for_vT(const sstd_yaml::command& rhs); + bool yaml_load ( sstd::terp::var & ret_yml, const char* s); bool yaml_load ( sstd::terp::var & ret_yml, const std::string& s); bool yaml_load_all(std::vector& ret_vYml, const char* s); diff --git a/sstd/src/memory/terp/print.cpp b/sstd/src/memory/terp/print.cpp index 4e736a3d..6c066103 100644 --- a/sstd/src/memory/terp/print.cpp +++ b/sstd/src/memory/terp/print.cpp @@ -20,9 +20,9 @@ void _print_terp_str(const sstd::terp::var& rhs){ } void _print_terp_list_internal(const sstd::terp::var& rhs){ switch(rhs.typeNum()){ - case sstd::num_str : { _print_terp_str (rhs); } break; - case sstd::num_vec_void_ptr : { _print_terp_list(rhs); } break; - case sstd::num_hash_str_void_ptr: { _print_terp_hash(rhs); } break; + case sstd::num_str : { _print_terp_str (rhs); } break; + case sstd::num_vec_terp_var : { _print_terp_list(rhs); } break; + case sstd::num_hash_terp_var: { _print_terp_hash(rhs); } break; case sstd::num_null: {} break; default: { sstd::pdbg("ERROR"); } break; } @@ -47,9 +47,9 @@ void _print_terp_hash(const sstd::terp::var& rhs){ #define sstd_print_terp_var_base(rhs) \ switch(rhs.typeNum()){ \ - case sstd::num_str : { _print_terp_str (rhs); } break; \ - case sstd::num_vec_void_ptr : { _print_terp_list(rhs); } break; \ - case sstd::num_hash_str_void_ptr: { _print_terp_hash(rhs); } break; \ + case sstd::num_str : { _print_terp_str (rhs); } break; \ + case sstd::num_vec_terp_var : { _print_terp_list(rhs); } break; \ + case sstd::num_hash_terp_var: { _print_terp_hash(rhs); } break; \ case sstd::num_null: {} break; \ default: { sstd::pdbg("ERROR"); } break; \ } diff --git a/sstd/src/memory/terp/terp.cpp b/sstd/src/memory/terp/terp.cpp index ad8c3426..ef5255e4 100644 --- a/sstd/src/memory/terp/terp.cpp +++ b/sstd/src/memory/terp/terp.cpp @@ -13,8 +13,9 @@ std::string* _cast2str (void* rhs){ return ( std::vector* _cast2vec (void* rhs){ return (std::vector*)rhs; } std::unordered_map* _cast2hash(void* rhs){ return (std::unordered_map*)rhs; } -#define STR (*(std::string*)src.ptr()) -void sstd::terp::_to( bool & dst, const sstd::void_ptr& src){ +#define STR (*(std::string*)src.p()) + +void sstd::terp::_to( bool & dst, const sstd::terp::var& src){ if(STR=="true"||STR=="yes"||STR=="on"){ dst = true; }else if(STR=="false"||STR=="no"||STR=="off"){ @@ -23,29 +24,31 @@ void sstd::terp::_to( bool & dst, const sstd::void_ptr& src){ sstd::pdbg_err("input string is not bool type.\n"); } } -void sstd::terp::_to( char & dst, const sstd::void_ptr& src){ dst = STR.size()>=1 ? STR[0] : 0; } -void sstd::terp::_to( int8 & dst, const sstd::void_ptr& src){ dst = strtol(STR.c_str(), NULL, 10); } -void sstd::terp::_to( int16 & dst, const sstd::void_ptr& src){ dst = strtol(STR.c_str(), NULL, 10); } -void sstd::terp::_to( int32 & dst, const sstd::void_ptr& src){ dst = strtol(STR.c_str(), NULL, 10); } -void sstd::terp::_to( int64 & dst, const sstd::void_ptr& src){ dst = strtoll(STR.c_str(), NULL, 10); } -void sstd::terp::_to( uint8 & dst, const sstd::void_ptr& src){ dst = strtoul(STR.c_str(), NULL, 10); } -void sstd::terp::_to( uint16 & dst, const sstd::void_ptr& src){ dst = strtoul(STR.c_str(), NULL, 10); } -void sstd::terp::_to( uint32 & dst, const sstd::void_ptr& src){ dst = strtoul(STR.c_str(), NULL, 10); } -void sstd::terp::_to( uint64 & dst, const sstd::void_ptr& src){ dst = strtoull(STR.c_str(), NULL, 10); } -void sstd::terp::_to( float & dst, const sstd::void_ptr& src){ dst = strtof(STR.c_str(), NULL); } -void sstd::terp::_to( double & dst, const sstd::void_ptr& src){ dst = strtod(STR.c_str(), NULL); } -void sstd::terp::_to(const char*& dst, const sstd::void_ptr& src){ dst = STR.c_str(); } -void sstd::terp::_to(std::string& dst, const sstd::void_ptr& src){ dst = STR; } -void sstd::terp::_to(std::string& dst, const std::string & src){ dst = src; } +void sstd::terp::_to( char & dst, const sstd::terp::var& src){ dst = STR.size()>=1 ? STR[0] : 0; } +void sstd::terp::_to( int8 & dst, const sstd::terp::var& src){ dst = strtol(STR.c_str(), NULL, 10); } +void sstd::terp::_to( int16 & dst, const sstd::terp::var& src){ dst = strtol(STR.c_str(), NULL, 10); } +void sstd::terp::_to( int32 & dst, const sstd::terp::var& src){ dst = strtol(STR.c_str(), NULL, 10); } +void sstd::terp::_to( int64 & dst, const sstd::terp::var& src){ dst = strtoll(STR.c_str(), NULL, 10); } +void sstd::terp::_to( uint8 & dst, const sstd::terp::var& src){ dst = strtoul(STR.c_str(), NULL, 10); } +void sstd::terp::_to( uint16 & dst, const sstd::terp::var& src){ dst = strtoul(STR.c_str(), NULL, 10); } +void sstd::terp::_to( uint32 & dst, const sstd::terp::var& src){ dst = strtoul(STR.c_str(), NULL, 10); } +void sstd::terp::_to( uint64 & dst, const sstd::terp::var& src){ dst = strtoull(STR.c_str(), NULL, 10); } +void sstd::terp::_to( float & dst, const sstd::terp::var& src){ dst = strtof(STR.c_str(), NULL); } +void sstd::terp::_to( double & dst, const sstd::terp::var& src){ dst = strtod(STR.c_str(), NULL); } +void sstd::terp::_to(const char*& dst, const sstd::terp::var& src){ dst = STR.c_str(); } +void sstd::terp::_to(std::string& dst, const sstd::terp::var& src){ dst = STR; } +void sstd::terp::_to(std::string& dst, const std::string & src){ dst = src; } #undef STR +#define NULL_CHECK(p) if(p==NULL){ sstd::pdbg_err("NULL pointer is detected\n"); return; } + //----------------------------------------------------------------------------------------------------------------------------------------------- // sstd::terp::iterator // constructors -sstd::terp::iterator::iterator(): _typeNum(sstd::num_null) {} -sstd::terp::iterator::iterator(const _v_iterator& rhs){ _typeNum=sstd::num_vec_void_ptr; _v_itr=rhs; } -sstd::terp::iterator::iterator(const _h_iterator& rhs){ _typeNum=sstd::num_hash_str_void_ptr; _h_itr=rhs; } +sstd::terp::iterator::iterator(): _type(sstd::num_null) {} +sstd::terp::iterator::iterator(const _v_iterator& rhs){ this->_type=sstd::num_vec_terp_var; _v_itr=rhs; } +sstd::terp::iterator::iterator(const _h_iterator& rhs){ this->_type=sstd::num_hash_terp_var; _h_itr=rhs; } sstd::terp::iterator::~iterator(){} //--- @@ -56,8 +59,8 @@ const sstd::terp::_h_iterator& sstd::terp::iterator::_h_itr_R() const { return _ //--- sstd::terp::iterator sstd::terp::iterator::operator+(const int rhs){ - switch(_typeNum){ - case sstd::num_vec_void_ptr: { return iterator( _v_itr + rhs ); } break; + switch(this->_type){ + case sstd::num_vec_terp_var: { return iterator( _v_itr + rhs ); } break; default: { sstd::pdbg_err("ERROR\n"); } } return iterator(); @@ -66,8 +69,8 @@ sstd::terp::iterator sstd::terp::iterator::operator+(const int rhs){ //--- sstd::terp::var sstd::terp::iterator::second(){ - switch(_typeNum){ - case sstd::num_hash_str_void_ptr: { + switch(this->_type){ + case sstd::num_hash_terp_var: { return sstd::terp::var((*_h_itr).second); } break; default: { sstd::pdbg_err("ERROR\n"); } @@ -78,23 +81,71 @@ sstd::terp::var sstd::terp::iterator::second(){ //--- const bool sstd::terp::iterator::operator!=(const iterator& rhs) const { - switch(_typeNum){ - case sstd::num_vec_void_ptr: { return _v_itr != rhs._v_itr_R(); } break; - case sstd::num_hash_str_void_ptr: { return _h_itr != rhs._h_itr_R(); } break; + switch(this->_type){ + case sstd::num_vec_terp_var: { return _v_itr != rhs._v_itr_R(); } break; + case sstd::num_hash_terp_var: { return _h_itr != rhs._h_itr_R(); } break; default: { sstd::pdbg_err("ERROR\n"); } } return false; } sstd::terp::iterator sstd::terp::iterator::operator++(){ - switch(_typeNum){ - case sstd::num_vec_void_ptr: { ++_v_itr; } break; - case sstd::num_hash_str_void_ptr: { ++_h_itr; } break; + switch(this->_type){ + case sstd::num_vec_terp_var: { ++_v_itr; } break; + case sstd::num_hash_terp_var: { ++_h_itr; } break; default: { sstd::pdbg_err("ERROR\n"); } } return *this; } +//----------------------------------------------------------------------------------------------------------------------------------------------- +// sstd::terp::hash + +sstd::terp::var sstd::terp::hash(uint allocate_size){ + sstd::terp::var r; + r.type_RW() = num_hash_terp_var; + r.p_RW() = new std::unordered_map(allocate_size); + return r; +} +sstd::terp::var sstd::terp::hash(){ return sstd::terp::hash(0); } + +//----------------------------------------------------------------------------------------------------------------------------------------------- +// sstd::terp::list + +sstd::terp::var sstd::terp::list(uint allocate_size){ + sstd::terp::var r; + r.type_RW() = num_vec_terp_var; + r.p_RW() = new std::vector(allocate_size); + return r; +} +sstd::terp::var sstd::terp::list(){ + sstd::terp::var r; + r.type_RW() = num_vec_terp_var; + r.p_RW() = new std::vector(); + return r; +} + +//----------------------------------------------------------------------------------------------------------------------------------------------- +// sstd::terp::null + +sstd::terp::var sstd::terp::null(){ return sstd::terp::var(); } + +//----------------------------------------------------------------------------------------------------------------------------------------------- +// type check + +bool sstd::terp::isHash (const sstd::terp::var& rhs){ + return ( rhs.typeNum()==sstd::num_hash_str_void_ptr || rhs.typeNum()==sstd::num_hash_terp_var ); +} +bool sstd::terp::isList (const sstd::terp::var& rhs){ + return rhs.typeNum()==sstd::num_vec_terp_var; +} +bool sstd::terp::isNull (const sstd::terp::var& rhs){ + return rhs.typeNum()==sstd::num_null; +} +bool sstd::terp::isValue(const sstd::terp::var& rhs){ + return rhs.typeNum()==sstd::num_str; +} + //----------------------------------------------------------------------------------------------------------------------------------------------- // sstd::terp::var @@ -118,41 +169,172 @@ std::string _format(double rhs){ } // constructors -sstd::terp::var::var(){ _p = &_vp; } -sstd::terp::var::var(const var& rhs){ _vp=*rhs.p(); _p=&_vp; } -sstd::terp::var::var(const sstd::void_ptr& vp_in){ _vp=vp_in; _p=&_vp; } -sstd::terp::var::var( sstd::void_ptr* p_in){ _p = p_in; } -sstd::terp::var::var( bool rhs){ _p=&_vp; (*_p).overwrite(new std::string(rhs?"true":"false")); } -sstd::terp::var::var( char rhs){ _p=&_vp; (*_p).overwrite(new std::string({rhs})); } -sstd::terp::var::var( int8 rhs){ _p=&_vp; (*_p).overwrite(new std::string(sstd::ssprintf("%d", rhs))); } -sstd::terp::var::var( int16 rhs){ _p=&_vp; (*_p).overwrite(new std::string(sstd::ssprintf("%d", rhs))); } -sstd::terp::var::var( int32 rhs){ _p=&_vp; (*_p).overwrite(new std::string(sstd::ssprintf("%d", rhs))); } -sstd::terp::var::var( int64 rhs){ _p=&_vp; (*_p).overwrite(new std::string(sstd::ssprintf("%ld", rhs))); } -sstd::terp::var::var( uint8 rhs){ _p=&_vp; (*_p).overwrite(new std::string(sstd::ssprintf("%u", rhs))); } -sstd::terp::var::var( uint16 rhs){ _p=&_vp; (*_p).overwrite(new std::string(sstd::ssprintf("%u", rhs))); } -sstd::terp::var::var( uint32 rhs){ _p=&_vp; (*_p).overwrite(new std::string(sstd::ssprintf("%u", rhs))); } -sstd::terp::var::var( uint64 rhs){ _p=&_vp; (*_p).overwrite(new std::string(sstd::ssprintf("%lu", rhs))); } -sstd::terp::var::var( float rhs){ _p=&_vp; (*_p).overwrite(new std::string(sstd::ssprintf(_format(rhs).c_str(), rhs))); } -sstd::terp::var::var( double rhs){ _p=&_vp; (*_p).overwrite(new std::string(sstd::ssprintf(_format(rhs).c_str(), rhs))); } -sstd::terp::var::var(const char* rhs){ _p=&_vp; (*_p).overwrite(new std::string(rhs)); } -sstd::terp::var::var(const std::string& rhs){ _p=&_vp; (*_p).overwrite(new std::string(rhs)); } -sstd::terp::var::~var(){} +sstd::terp::var::var(): _type(sstd::num_null), _p(NULL) {} +sstd::terp::var::var(const class var& rhs): _type(sstd::num_null), _p(NULL) { copy(rhs); } +sstd::terp::var::var( class var&& rhs): _type(sstd::num_null), _p(NULL) { free(); move(std::move(rhs)); } +sstd::terp::var::var( bool rhs){ _type=sstd::num_str; _p=new std::string(rhs?"true":"false"); } +sstd::terp::var::var( char rhs){ _type=sstd::num_str; _p=new std::string({rhs}); } +sstd::terp::var::var( int8 rhs){ _type=sstd::num_str; _p=new std::string(sstd::ssprintf("%d", rhs)); } +sstd::terp::var::var( int16 rhs){ _type=sstd::num_str; _p=new std::string(sstd::ssprintf("%d", rhs)); } +sstd::terp::var::var( int32 rhs){ _type=sstd::num_str; _p=new std::string(sstd::ssprintf("%d", rhs)); } +sstd::terp::var::var( int64 rhs){ _type=sstd::num_str; _p=new std::string(sstd::ssprintf("%ld", rhs)); } +sstd::terp::var::var( uint8 rhs){ _type=sstd::num_str; _p=new std::string(sstd::ssprintf("%u", rhs)); } +sstd::terp::var::var( uint16 rhs){ _type=sstd::num_str; _p=new std::string(sstd::ssprintf("%u", rhs)); } +sstd::terp::var::var( uint32 rhs){ _type=sstd::num_str; _p=new std::string(sstd::ssprintf("%u", rhs)); } +sstd::terp::var::var( uint64 rhs){ _type=sstd::num_str; _p=new std::string(sstd::ssprintf("%lu", rhs)); } +sstd::terp::var::var( float rhs){ _type=sstd::num_str; _p=new std::string(sstd::ssprintf(_format(rhs).c_str(), rhs)); } +sstd::terp::var::var( double rhs){ _type=sstd::num_str; _p=new std::string(sstd::ssprintf(_format(rhs).c_str(), rhs)); } +sstd::terp::var::var(const char* rhs): _type(sstd::num_str), _p(new std::string(rhs)) {} +sstd::terp::var::var(const std::string& rhs){ _type=sstd::num_str; _p=new std::string(rhs); } + +sstd::terp::var::~var(){ sstd::terp::var::free(); } + +//--- +/* +void sstd::terp::var::list(uint allocate_size){ + printf("in l\n"); + sstd::terp::var::free(); + printf("in l2\n"); + this->_p = new std::vector(allocate_size); + this->_type = num_vec_terp_var; +} +void sstd::terp::var::list(){ + sstd::terp::var::free(); + this->_p = new std::vector(); + this->_type = num_vec_terp_var; +} +*/ +//--- +// internal + +void* sstd::terp::var::p() const { return this->_p; } +uint sstd::terp::var::type() const { return this->_type; } +void*& sstd::terp::var::p_RW(){ return this->_p; } +uint & sstd::terp::var::type_RW(){ return this->_type; } //--- +// common -sstd::terp::var sstd::terp::var::operator=(const char* rhs){ - (*_p).overwrite(new std::string(rhs)); - return *this; +void sstd::terp::var::copy(const class sstd::terp::var& rhs){ + sstd::terp::var::free(); + + this->_type = rhs.type(); + if(rhs.p()==NULL){ this->_p=NULL; return; } + switch (this->_type){ + case sstd::num_null : {} break; + + case sstd::num_bool : { this->_p = new bool(*( bool *)rhs.p()); } break; + case sstd::num_char : { this->_p = new char(*( char *)rhs.p()); } break; + case sstd::num_int8 : { this->_p = new int8 (*( int8 *)rhs.p()); } break; + case sstd::num_int16 : { this->_p = new int16(*( int16*)rhs.p()); } break; + case sstd::num_int32 : { this->_p = new int32(*( int32*)rhs.p()); } break; + case sstd::num_int64 : { this->_p = new int64(*( int64*)rhs.p()); } break; + case sstd::num_uint8 : { this->_p = new uint8 (*( uint8 *)rhs.p()); } break; + case sstd::num_uint16 : { this->_p = new uint16(*( uint16*)rhs.p()); } break; + case sstd::num_uint32 : { this->_p = new uint32(*( uint32*)rhs.p()); } break; + case sstd::num_uint64 : { this->_p = new uint64(*( uint64*)rhs.p()); } break; + case sstd::num_float : { this->_p = new float(*( float*)rhs.p()); } break; + case sstd::num_double : { this->_p = new double(*( double*)rhs.p()); } break; + case sstd::num_str : { this->_p = new std::string(*( std::string*)rhs.p()); } break; +// case sstd::num_void_ptr: { this->_p = new sstd::void_ptr(*(sstd::void_ptr*)rhs.p()); } break; + + case sstd::num_vec_bool : { this->_p = new std::vector< bool>(*(std::vector< bool>*)rhs.p()); } break; + case sstd::num_vec_char : { this->_p = new std::vector< char>(*(std::vector< char>*)rhs.p()); } break; + case sstd::num_vec_int8 : { this->_p = new std::vector< int8 >(*(std::vector< int8 >*)rhs.p()); } break; + case sstd::num_vec_int16 : { this->_p = new std::vector< int16>(*(std::vector< int16>*)rhs.p()); } break; + case sstd::num_vec_int32 : { this->_p = new std::vector< int32>(*(std::vector< int32>*)rhs.p()); } break; + case sstd::num_vec_int64 : { this->_p = new std::vector< int64>(*(std::vector< int64>*)rhs.p()); } break; + case sstd::num_vec_uint8 : { this->_p = new std::vector< uint8 >(*(std::vector< uint8 >*)rhs.p()); } break; + case sstd::num_vec_uint16 : { this->_p = new std::vector< uint16>(*(std::vector< uint16>*)rhs.p()); } break; + case sstd::num_vec_uint32 : { this->_p = new std::vector< uint32>(*(std::vector< uint32>*)rhs.p()); } break; + case sstd::num_vec_uint64 : { this->_p = new std::vector< uint64>(*(std::vector< uint64>*)rhs.p()); } break; + case sstd::num_vec_float : { this->_p = new std::vector< float>(*(std::vector< float>*)rhs.p()); } break; + case sstd::num_vec_double : { this->_p = new std::vector< double>(*(std::vector< double>*)rhs.p()); } break; + case sstd::num_vec_str : { this->_p = new std::vector< std::string>(*(std::vector< std::string>*)rhs.p()); } break; +// case sstd::num_vec_void_ptr: { this->_p = new std::vector(*(std::vector*)rhs.p()); } break; + + case sstd::num_hash_str_str : { this->_p = new std::unordered_map(*(std::unordered_map*)rhs.p()); } break; +// case sstd::num_hash_str_void_ptr : { this->_p = new std::unordered_map(*(std::unordered_map*)rhs.p()); } break; +// case sstd::num_hash_void_ptr_void_ptr: { this->_p = new std::unordered_map(*(std::unordered_map*)rhs.p()); } break; + + case sstd::num_vec_terp_var: { this->_p = new std::vector(*(std::vector*)rhs.p()); } break; + case sstd::num_hash_terp_var: { this->_p = new std::unordered_map(*(std::unordered_map*)rhs.p()); } break; + + default: { sstd::pdbg("ERROR: allocating memory is failed. typeNum '%d' is not defined.", this->_type); } break; + + } +} + +void sstd::terp::var::move( class sstd::terp::var&& rhs){ + this->_type = rhs.type(); rhs.type_RW() = sstd::num_null; + this->_p = rhs.p(); rhs.p_RW() = NULL; +} + +void sstd::terp::var::free(){ + if(this->_p==NULL){ return; } + + switch (this->_type){ + case sstd::num_null : {} break; + case sstd::num_bool : { delete ( bool*)_p; } break; + case sstd::num_char : { delete ( char*)_p; } break; + case sstd::num_int8 : { delete ( int8 *)_p; } break; + case sstd::num_int16 : { delete ( int16*)_p; } break; + case sstd::num_int32 : { delete ( int32*)_p; } break; + case sstd::num_int64 : { delete ( int64*)_p; } break; + case sstd::num_uint8 : { delete ( uint8 *)_p; } break; + case sstd::num_uint16 : { delete ( uint16*)_p; } break; + case sstd::num_uint32 : { delete ( uint32*)_p; } break; + case sstd::num_uint64 : { delete ( uint64*)_p; } break; + case sstd::num_float : { delete ( float*)_p; } break; + case sstd::num_double : { delete ( double*)_p; } break; + case sstd::num_str : { delete ( std::string*)_p; } break; +// case sstd::num_void_ptr: { delete (sstd::void_ptr*)_p; } break; // DELETE LATER + + case sstd::num_vec_bool : { delete (std::vector< bool>*)_p; } break; + case sstd::num_vec_char : { delete (std::vector< char>*)_p; } break; + case sstd::num_vec_int8 : { delete (std::vector< int8 >*)_p; } break; + case sstd::num_vec_int16 : { delete (std::vector< int16>*)_p; } break; + case sstd::num_vec_int32 : { delete (std::vector< int32>*)_p; } break; + case sstd::num_vec_int64 : { delete (std::vector< int64>*)_p; } break; + case sstd::num_vec_uint8 : { delete (std::vector< uint8 >*)_p; } break; + case sstd::num_vec_uint16 : { delete (std::vector< uint16>*)_p; } break; + case sstd::num_vec_uint32 : { delete (std::vector< uint32>*)_p; } break; + case sstd::num_vec_uint64 : { delete (std::vector< uint64>*)_p; } break; + case sstd::num_vec_float : { delete (std::vector< float>*)_p; } break; + case sstd::num_vec_double : { delete (std::vector< double>*)_p; } break; + case sstd::num_vec_str : { delete (std::vector< std::string>*)_p; } break; +// case sstd::num_vec_void_ptr: { delete (std::vector*)_p; } break; // DELETE LATER + + case sstd::num_hash_str_str : { delete (std::unordered_map*)_p; } break; +// case sstd::num_hash_str_void_ptr : { delete (std::unordered_map*)_p; } break; +// case sstd::num_hash_void_ptr_void_ptr: { delete (std::unordered_map*)_p; } break; + + case sstd::num_vec_terp_var: { delete (std::vector*)_p; } break; + case sstd::num_hash_terp_var: { delete (std::unordered_map*)_p; } break; + + default: { sstd::pdbg("ERROR: free() memory is failed. typeNum '%d' is not defined.", this->_type); } break; + } + + this->_p=NULL; } -sstd::terp::var sstd::terp::var::operator=(const sstd::terp::var& rhs){ - *_p = *rhs.p(); + +sstd::terp::var& sstd::terp::var::operator=(const sstd::terp::var& rhs){ + copy(rhs); return *this; } -//--- +template +void sstd::terp::var::_overwrite(T* ptr){ + sstd::terp::var::free(); + this->_type = sstd::type2num(T()); + this->_p = ptr; +} +sstd::terp::var& sstd::terp::var::operator=(const char* rhs){ + _overwrite(new std::string(rhs)); + return *this; +} bool _is_equal(const sstd::terp::var& lhs, const sstd::terp::var& rhs); // forward declaration - bool _is_equal_list(const sstd::terp::var& lhs, const sstd::terp::var& rhs){ if(lhs.size()!=rhs.size()){ return false; } @@ -177,13 +359,13 @@ bool _is_equal_hash(const sstd::terp::var& lhs, const sstd::terp::var& rhs){ return true; } bool _is_equal(const sstd::terp::var& lhs, const sstd::terp::var& rhs){ - if(lhs.typeNum()!=rhs.typeNum()){ return false; } + if(lhs.type()!=rhs.type()){ return false; } switch(lhs.typeNum()){ - case sstd::num_str: { return lhs.to()==rhs.to(); } break; - case sstd::num_vec_void_ptr: { return _is_equal_list(lhs, rhs); } break; - case sstd::num_hash_str_void_ptr: { return _is_equal_hash(lhs, rhs); } break; - case sstd::num_null: { return true; } break; + case sstd::num_str: { return lhs.to()==rhs.to(); } break; + case sstd::num_vec_terp_var: { return _is_equal_list(lhs, rhs); } break; + case sstd::num_hash_terp_var: { return _is_equal_hash(lhs, rhs); } break; + case sstd::num_null: { return true; } break; default: { sstd::pdbg_err("ERROR\n"); } break; } @@ -192,59 +374,56 @@ bool _is_equal(const sstd::terp::var& lhs, const sstd::terp::var& rhs){ bool sstd::terp::var::operator==(const sstd::terp::var& rhs){ return _is_equal(*this, rhs); } bool sstd::terp::var::operator!=(const sstd::terp::var& rhs){ return !_is_equal(*this, rhs); } -//--- +#define _CAST2VEC(_P) (*(std::vector*)_P) +#define _CAST2HASH(_P) (*(std::unordered_map*)_P) -sstd::terp::var _ope_subscript_idx_base(const sstd::void_ptr* _p, const int idx){ - switch((*_p).typeNum()){ - case sstd::num_vec_void_ptr: { sstd::void_ptr* p=(sstd::void_ptr*)&(*_cast2vec((*_p).ptr()))[idx]; return sstd::terp::var( p ); } break; - default: { sstd::pdbg_err("Ope[](char*) is failed. Unexpedted data type. sstd::terp::var takes \"sstd::terp::hash()\" type, but treat as a \"sstd::terp::list()\".\n"); } break; - } - return sstd::terp::var(); -} -sstd::terp::var _ope_subscript_pKey_base(const sstd::void_ptr* _p, const char* pKey){ - switch((*_p).typeNum()){ - case sstd::num_hash_str_void_ptr: { sstd::void_ptr* p=(sstd::void_ptr*)&(*_cast2hash((*_p).ptr()))[pKey]; return sstd::terp::var( p ); } break; - default: { sstd::pdbg_err("Ope[](char*) is failed. Unexpedted data type. sstd::terp::var takes \"sstd::terp::list()\" type, but treat as a \"sstd::terp::hash()\".\n"); } break; - } - return sstd::terp::var(); -} - sstd::terp::var sstd::terp::var::operator[](const int idx) { return _ope_subscript_idx_base(_p, idx); } -const sstd::terp::var sstd::terp::var::operator[](const int idx) const { return _ope_subscript_idx_base(_p, idx); } - sstd::terp::var sstd::terp::var::operator[](const char* pKey) { return _ope_subscript_pKey_base(_p, pKey); } -const sstd::terp::var sstd::terp::var::operator[](const char* pKey) const { return _ope_subscript_pKey_base(_p, pKey); } +#define _OPE_SUBSCRIPT_IDX_BASE() \ + switch(_type){ \ + case sstd::num_vec_terp_var: { return _CAST2VEC(this->_p)[idx]; } break; \ + default: { sstd::pdbg_err("Ope[](char*) is failed. Unexpedted data type. sstd::terp::var takes \"sstd::terp::hash()\" type, but treat as a \"sstd::terp::list()\".\n"); } break; \ + } \ + return *this; +#define _OPE_SUBSCRIPT_KEY_BASE(pKey) \ + switch(_type){ \ + case sstd::num_hash_terp_var: { return _CAST2HASH(_p)[pKey]; } break; \ + default: { sstd::pdbg_err("Ope[](char*) is failed. Unexpedted data type. sstd::terp::var takes \"sstd::terp::list()\" type, but treat as a \"sstd::terp::hash()\".\n"); } break; \ + } \ + return *this; + sstd::terp::var& sstd::terp::var::operator[](const int idx) { _OPE_SUBSCRIPT_IDX_BASE(); } +const sstd::terp::var& sstd::terp::var::operator[](const int idx) const { _OPE_SUBSCRIPT_IDX_BASE(); } + sstd::terp::var& sstd::terp::var::operator[](const char* pKey) { _OPE_SUBSCRIPT_KEY_BASE(pKey); } +const sstd::terp::var& sstd::terp::var::operator[](const char* pKey) const { _OPE_SUBSCRIPT_KEY_BASE(pKey); } + sstd::terp::var& sstd::terp::var::operator[](const std::string key) { _OPE_SUBSCRIPT_KEY_BASE(key.c_str()); } +const sstd::terp::var& sstd::terp::var::operator[](const std::string key) const { _OPE_SUBSCRIPT_KEY_BASE(key.c_str()); } //--- const sstd::terp::_v_iterator _v_begin(void* p_in){ - std::vector* p = _cast2vec(p_in); - return (*p).begin(); + return _CAST2VEC(p_in).begin(); } const sstd::terp::_v_iterator _v_end(void* p_in){ - std::vector* p = _cast2vec(p_in); - return (*p).end(); + return _CAST2VEC(p_in).end(); } const sstd::terp::_h_iterator _h_begin(void* p_in){ - std::unordered_map* p = _cast2hash(p_in); - return (*p).begin(); + return _CAST2HASH(p_in).begin(); } const sstd::terp::_h_iterator _h_end(void* p_in){ - std::unordered_map* p = _cast2hash(p_in); - return (*p).end(); + return _CAST2HASH(p_in).end(); } sstd::terp::iterator sstd::terp::var::begin() const { - switch((*_p).typeNum()){ - case sstd::num_vec_void_ptr: { return sstd::terp::iterator(_v_begin((*_p).ptr())); } break; - case sstd::num_hash_str_void_ptr: { return sstd::terp::iterator(_h_begin((*_p).ptr())); } break; - case sstd::num_null: {} break; + switch(_type){ + case sstd::num_vec_terp_var: { return sstd::terp::iterator(_v_begin(_p)); } break; + case sstd::num_hash_terp_var: { return sstd::terp::iterator(_h_begin(_p)); } break; + case sstd::num_null: {} break; default: { sstd::pdbg_err("ERROR\n"); } } return sstd::terp::iterator(); } sstd::terp::iterator sstd::terp::var::end() const { - switch((*_p).typeNum()){ - case sstd::num_vec_void_ptr: { return sstd::terp::iterator(_v_end((*_p).ptr())); } break; - case sstd::num_hash_str_void_ptr: { return sstd::terp::iterator(_h_end((*_p).ptr())); } break; - case sstd::num_null: {} break; + switch(_type){ + case sstd::num_vec_terp_var: { return sstd::terp::iterator(_v_end(_p)); } break; + case sstd::num_hash_terp_var: { return sstd::terp::iterator(_h_end(_p)); } break; + case sstd::num_null: {} break; default: { sstd::pdbg_err("ERROR\n"); } } return sstd::terp::iterator(); @@ -252,9 +431,15 @@ sstd::terp::iterator sstd::terp::var::end() const { //--- +uint sstd::terp::var::typeNum() const { return this->_type; } +std::string sstd::terp::var::typeStr() const { return sstd::typeNum2str(_type); } + +//--- +// for hash type + uint sstd::terp::var::bucket_count(){ - switch((*_p).typeNum()){ - case sstd::num_hash_str_void_ptr: { return (*_cast2hash((*_p).ptr())).bucket_count(); } break; + switch(_type){ + case sstd::num_hash_terp_var: { return _CAST2HASH(_p).bucket_count(); } break; default: { sstd::pdbg_err("ERROR\n"); } break; } return 0; @@ -263,18 +448,17 @@ uint sstd::terp::var::bucket_count(){ //--- sstd::terp::iterator sstd::terp::var::erase(const sstd::terp::iterator& rhs){ - switch((*_p).typeNum()){ - case sstd::num_vec_void_ptr: { return sstd::terp::iterator( _cast2vec((*_p).ptr())->erase(rhs._v_itr_R()) ); } break; - //case sstd::num_hash_str_void_ptr: { return _cast2hash((*_p).ptr())->erase(pKey); } break; - case sstd::num_null: {} break; + switch(_type){ + case sstd::num_vec_terp_var: { return sstd::terp::iterator( _CAST2VEC(_p).erase(rhs._v_itr_R()) ); } break; + case sstd::num_null: {} break; default: { sstd::pdbg_err("ERROR\n"); } } return sstd::terp::iterator(); } uint sstd::terp::var::erase(const char* pKey){ - switch((*_p).typeNum()){ - case sstd::num_hash_str_void_ptr: { return _cast2hash((*_p).ptr())->erase(pKey); } break; - case sstd::num_null: {} break; + switch(_type){ + case sstd::num_hash_terp_var: { return _CAST2HASH(_p).erase(pKey); } break; + case sstd::num_null: {} break; default: { sstd::pdbg_err("ERROR\n"); } } return 0; @@ -283,103 +467,65 @@ uint sstd::terp::var::erase(const char* pKey){ //--- sstd::terp::iterator sstd::terp::var::find(const char* pKey) const { - switch((*_p).typeNum()){ - case sstd::num_hash_str_void_ptr: { return sstd::terp::iterator( _cast2hash((*_p).ptr())->find(pKey) ); } break; - case sstd::num_null: {} break; + switch(_type){ + case sstd::num_hash_terp_var: { return sstd::terp::iterator( _CAST2HASH(_p).find(pKey) ); } break; + case sstd::num_null: {} break; default: { sstd::pdbg_err("ERROR\n"); } } return sstd::terp::iterator(); } +sstd::terp::iterator sstd::terp::var::find(const std::string key) const { + return sstd::terp::var::find(key.c_str()); +} //--- - -sstd::void_ptr* sstd::terp::var::p() const { return _p; } - -//--- +// for list type void sstd::terp::var::pop_back(){ - switch((*_p).typeNum()){ - case sstd::num_vec_void_ptr: { _cast2vec((*_p).ptr())->pop_back(); return; } break; - case sstd::num_null: {} break; + NULL_CHECK(_p); + switch(_type){ + case sstd::num_vec_terp_var: { if(_CAST2VEC(this->_p).size()==0){return;} _CAST2VEC(this->_p).pop_back(); return; } break; + case sstd::num_null: {} break; default: { sstd::pdbg_err("ERROR\n"); } } return; } -//--- - +void sstd::terp::var::push_back(){ // push_back null + NULL_CHECK(_p); + if(_type!=sstd::num_vec_terp_var){ sstd::pdbg_err("push_back(char*) is failed. Unexpedted data type. This function requires sstd::num_vec_terp_var type, but takes %s type.\n", sstd::typeNum2str(this->_type).c_str()); return; } + _CAST2VEC(_p).push_back(sstd::terp::null()); +} void sstd::terp::var::push_back(const char* pRhs){ - if((*_p).typeNum()!=sstd::num_vec_void_ptr){ sstd::pdbg_err("push_back(char*) is failed. Unexpedted data type. This function requires sstd::num_vec_void_ptr type, but takes %s type.\n", sstd::typeNum2str((*_p).typeNum()).c_str()); return; } - (*_cast2vec((*_p).ptr())).push_back(new std::string(pRhs)); + NULL_CHECK(_p); + if(_type!=sstd::num_vec_terp_var){ sstd::pdbg_err("push_back(char*) is failed. Unexpedted data type. This function requires sstd::num_vec_terp_var type, but takes %s type.\n", sstd::typeNum2str(this->_type).c_str()); return; } + _CAST2VEC(_p).push_back(sstd::terp::var(pRhs)); } void sstd::terp::var::push_back(const sstd::terp::var& rhs){ - if((*_p).typeNum()!=sstd::num_vec_void_ptr){ sstd::pdbg_err("push_back(var&) is failed. Unexpedted data type. This function requires sstd::num_vec_void_ptr type, but takes %s type.\n", sstd::typeNum2str((*_p).typeNum()).c_str()); return; } - (*_cast2vec((*_p).ptr())).push_back(*rhs.p()); + NULL_CHECK(_p); + if(_type!=sstd::num_vec_terp_var){ sstd::pdbg_err("push_back(var&) is failed. Unexpedted data type. This function requires sstd::num_vec_terp_var type, but takes %s type.\n", sstd::typeNum2str(this->_type).c_str()); return; } + _CAST2VEC(_p).push_back(rhs); +} +void sstd::terp::var::push_back( sstd::terp::var&& rhs){ + NULL_CHECK(_p); + if(_type!=sstd::num_vec_terp_var){ sstd::pdbg_err("push_back(var&) is failed. Unexpedted data type. This function requires sstd::num_vec_terp_var type, but takes %s type.\n", sstd::typeNum2str(this->_type).c_str()); return; } + _CAST2VEC(_p).push_back(std::move(rhs)); // call move constructor of "sstd::void_ptr::void_ptr()" } - -//--- void sstd::terp::var::resize(uint len){ - switch((*_p).typeNum()){ - case sstd::num_vec_void_ptr: { return (*_cast2vec((*_p).ptr())).resize( len ); } break; + switch(_type){ + case sstd::num_vec_terp_var: { _CAST2VEC(_p).resize( len ); } break; default: { sstd::pdbg_err("ERROR\n"); } break; } } - -//--- uint sstd::terp::var::size() const { - switch((*_p).typeNum()){ - case sstd::num_vec_void_ptr : { return (*_cast2vec ((*_p).ptr())).size(); } break; - case sstd::num_hash_str_void_ptr: { return (*_cast2hash((*_p).ptr())).size(); } break; + switch(_type){ + case sstd::num_vec_terp_var : { return _CAST2VEC (_p).size(); } break; + case sstd::num_hash_terp_var: { return _CAST2HASH(_p).size(); } break; default: { sstd::pdbg_err("ERROR\n"); } break; } return 0; } -//--- - -uint sstd::terp::var::typeNum() const { - return (*_p).typeNum(); -} -std::string sstd::terp::var::typeStr() const { - return sstd::typeNum2str((*_p).typeNum()); -} - -//----------------------------------------------------------------------------------------------------------------------------------------------- -// sstd::terp::hash - -sstd::terp::var sstd::terp::hash(uint allocate_size){ - sstd::terp::var r; - r.p()->overwrite(new std::unordered_map(allocate_size)); - return r; -} -sstd::terp::var sstd::terp::hash(){ return sstd::terp::hash(0); } - -//----------------------------------------------------------------------------------------------------------------------------------------------- -// sstd::terp::list - -sstd::terp::var sstd::terp::list(uint allocate_size){ - sstd::terp::var r; - r.p()->overwrite(new std::vector(allocate_size)); - return r; -} -sstd::terp::var sstd::terp::list(){ return sstd::terp::list(0); } - -//----------------------------------------------------------------------------------------------------------------------------------------------- -// type check - -bool sstd::terp::isHash (const sstd::terp::var& rhs){ - return ( rhs.typeNum()==sstd::num_hash_str_void_ptr || rhs.typeNum()==sstd::num_hash_void_ptr_void_ptr ); -} -bool sstd::terp::isList (const sstd::terp::var& rhs){ - return rhs.typeNum()==sstd::num_vec_void_ptr; -} -bool sstd::terp::isNull (const sstd::terp::var& rhs){ - return rhs.typeNum()==sstd::num_null; -} -bool sstd::terp::isValue(const sstd::terp::var& rhs){ - return rhs.typeNum()==sstd::num_str; -} - //----------------------------------------------------------------------------------------------------------------------------------------------- diff --git a/sstd/src/memory/terp/terp.hpp b/sstd/src/memory/terp/terp.hpp index f46ab96a..81daba1c 100644 --- a/sstd/src/memory/terp/terp.hpp +++ b/sstd/src/memory/terp/terp.hpp @@ -26,6 +26,9 @@ namespace sstd::terp{ var list(uint allocate_size); var list(); + // null + var null(); + // type check bool isHash (const sstd::terp::var& rhs); bool isList (const sstd::terp::var& rhs); @@ -37,95 +40,35 @@ namespace sstd::terp{ // for internal use namespace sstd::terp{ - // iterator - using _v_iterator = typename std::vector::const_iterator; - using _h_iterator = typename std::unordered_map::const_iterator; - // to (data type conversion) - void _to( bool & dst, const sstd::void_ptr& src); - void _to( char & dst, const sstd::void_ptr& src); - void _to( int8 & dst, const sstd::void_ptr& src); - void _to( int16 & dst, const sstd::void_ptr& src); - void _to( int32 & dst, const sstd::void_ptr& src); - void _to( int64 & dst, const sstd::void_ptr& src); - void _to( uint8 & dst, const sstd::void_ptr& src); - void _to( uint16 & dst, const sstd::void_ptr& src); - void _to( uint32 & dst, const sstd::void_ptr& src); - void _to( uint64 & dst, const sstd::void_ptr& src); - void _to( float & dst, const sstd::void_ptr& src); - void _to( double & dst, const sstd::void_ptr& src); - void _to(const char*& dst, const sstd::void_ptr& src); - void _to(std::string& dst, const sstd::void_ptr& src); + void _to( bool & dst, const sstd::terp::var& src); + void _to( char & dst, const sstd::terp::var& src); + void _to( int8 & dst, const sstd::terp::var& src); + void _to( int16 & dst, const sstd::terp::var& src); + void _to( int32 & dst, const sstd::terp::var& src); + void _to( int64 & dst, const sstd::terp::var& src); + void _to( uint8 & dst, const sstd::terp::var& src); + void _to( uint16 & dst, const sstd::terp::var& src); + void _to( uint32 & dst, const sstd::terp::var& src); + void _to( uint64 & dst, const sstd::terp::var& src); + void _to( float & dst, const sstd::terp::var& src); + void _to( double & dst, const sstd::terp::var& src); + void _to(const char*& dst, const sstd::terp::var& src); + void _to(std::string& dst, const sstd::terp::var& src); void _to(std::string& dst, const std::string & src); } -//----------------------------------------------------------------------------------------------------------------------------------------------- -// iterator - -class sstd::terp::iterator{ -private: - uint _typeNum; - _v_iterator _v_itr; - _h_iterator _h_itr; -public: - iterator(); - iterator(const _v_iterator& rhs); - iterator(const _h_iterator& rhs); - ~iterator(); - - //--- - - const _v_iterator& _v_itr_R() const; - const _h_iterator& _h_itr_R() const; - - //--- - - iterator operator+(const int rhs); - - //--- - - template - T first_to() const { - T ret = T(); - switch(_typeNum){ - case sstd::num_vec_void_ptr: { sstd::terp::_to(ret, (sstd::void_ptr)(*_v_itr) ); return ret; } break; - case sstd::num_hash_str_void_ptr: { sstd::terp::_to(ret, (std::string )(*_h_itr).first); return ret; } break; - default: { sstd::pdbg_err("ERROR\n"); } - } - return ret; - } - - template - T second_to() const { - T ret = T(); - switch(_typeNum){ - case sstd::num_hash_str_void_ptr: { sstd::terp::_to(ret, (sstd::void_ptr)(*_h_itr).second); return ret; } break; - default: { sstd::pdbg_err("ERROR\n"); } - } - return ret; - } - sstd::terp::var second(); - - //--- - - const bool operator!=(const iterator& rhs) const; - class iterator operator++(); - - //--- -}; - //----------------------------------------------------------------------------------------------------------------------------------------------- class sstd::terp::var{ private: - sstd::void_ptr _vp; - sstd::void_ptr* _p; + uint _type; + void* _p; public: var(); - var(const var& rhs); - var(const sstd::void_ptr& vp_in); - var( sstd::void_ptr* p_in); + var(const class var& rhs); + var( class var&& rhs); var(const bool rhs); var(const char rhs); var(const int8 rhs); @@ -145,21 +88,36 @@ class sstd::terp::var{ //--- // internal - sstd::void_ptr* p() const; + void* p() const; + uint type() const; + + void*& p_RW(); + uint & type_RW(); //--- // common + + void copy(const class sstd::terp::var& rhs); + void move( class sstd::terp::var&& rhs); + void free(); + + template + void _overwrite(T* ptr); - var operator=(const char* rhs); - var operator=(const sstd::terp::var& rhs); + var& operator=(const sstd::terp::var& rhs); + //var operator=( sstd::terp::var&& rhs); + + var& operator=(const char* rhs); bool operator==(const sstd::terp::var& rhs); bool operator!=(const sstd::terp::var& rhs); - var operator[](const int idx); - const var operator[](const int idx) const; - var operator[](const char* pKey); - const var operator[](const char* pKey) const; + var& operator[](const int idx); + const var& operator[](const int idx) const; + var& operator[](const char* pKey); + const var& operator[](const char* pKey) const; + var& operator[](const std::string key); + const var& operator[](const std::string key) const; sstd::terp::iterator begin() const; sstd::terp::iterator end () const; @@ -170,7 +128,8 @@ class sstd::terp::var{ template const T to() const { T ret = T(); - sstd::terp::_to(ret, *_p); + if(this->_p==NULL){ sstd::pdbg_err("NULL pointer is detected\n"); return ret; } + sstd::terp::_to(ret, *this); return ret; } @@ -185,17 +144,86 @@ class sstd::terp::var{ sstd::terp::iterator erase(const sstd::terp::iterator& rhs); uint erase(const char* pKey); - sstd::terp::iterator find(const char* pKey) const; + sstd::terp::iterator find(const char* pKey) const; + sstd::terp::iterator find(const std::string key) const; //--- // for list type +// void list(uint allocate_size); +// void list(); + void pop_back(); + void push_back(); // push_back null void push_back(const char* pRhs); - void push_back(const sstd::terp::var& rhs); + void push_back(const sstd::terp::var& rhs); + void push_back( sstd::terp::var&& rhs); void resize(uint len); }; //----------------------------------------------------------------------------------------------------------------------------------------------- +// iterator + +namespace sstd::terp{ + // iterator + using _v_iterator = typename std::vector::const_iterator; + using _h_iterator = typename std::unordered_map::const_iterator; +} + +//--- + +class sstd::terp::iterator{ +private: + uint _type; + _v_iterator _v_itr; + _h_iterator _h_itr; +public: + iterator(); + iterator(const _v_iterator& rhs); + iterator(const _h_iterator& rhs); + ~iterator(); + + //--- + + const _v_iterator& _v_itr_R() const; + const _h_iterator& _h_itr_R() const; + + //--- + + iterator operator+(const int rhs); + + //--- + + template + T first_to() const { + T ret = T(); + switch(this->_type){ + case sstd::num_vec_terp_var: { sstd::terp::_to(ret, (sstd::terp::var)(*_v_itr) ); return ret; } break; + case sstd::num_hash_terp_var: { sstd::terp::_to(ret, (std::string )(*_h_itr).first); return ret; } break; + default: { sstd::pdbg_err("ERROR\n"); } + } + return ret; + } + + template + T second_to() const { + T ret = T(); + switch(this->_type){ + case sstd::num_hash_terp_var: { sstd::terp::_to(ret, (sstd::terp::var)(*_h_itr).second); return ret; } break; + default: { sstd::pdbg_err("ERROR\n"); } + } + return ret; + } + sstd::terp::var second(); + + //--- + + const bool operator!=(const iterator& rhs) const; + class iterator operator++(); + + //--- +}; + +//----------------------------------------------------------------------------------------------------------------------------------------------- diff --git a/sstd/src/string/strEdit.cpp b/sstd/src/string/strEdit.cpp index 5ca3dd0b..97b62642 100755 --- a/sstd/src/string/strEdit.cpp +++ b/sstd/src/string/strEdit.cpp @@ -1,4 +1,6 @@ #include "strEdit.hpp" + +#include "strmatch.hpp" #include "../file/file.hpp" #include "../print/pdbg.hpp" #include @@ -114,7 +116,7 @@ std::vector _asAX_rmSpace(const char* str, const char X){ std::string buf; uint i=0; - while(str[i]!='\0'){ if(' '==str[i]){++i;}else{break;} } // skip space + while(str[i]!='\0'){ if(str[i]==' '){++i;}else{break;} } // skip space while(str[i]!='\0'){ if(X==str[i]){ sstd::rstrip_ow(buf); splitList.push_back(buf); buf.clear(); @@ -126,6 +128,7 @@ std::vector _asAX_rmSpace(const char* str, const char X){ } } if(buf.size()!=0){ sstd::rstrip_ow(buf); splitList.push_back(buf); } +// if(i>=1 && str[i-1]==X){ splitList.push_back(std::string()); } return splitList; } std::vector _asAX(const char* str, const char X){ @@ -147,6 +150,7 @@ std::vector _asAX(const char* str, const char X){ } // if(buf.size()!=0){ sstd::rstrip_ow(buf); splitList.push_back(buf); } if(buf.size()!=0){ splitList.push_back(buf); } + if(i>=1 && str[i-1]==X){ splitList.push_back(std::string()); } return splitList; } std::vector sstd::split(const char* str ){ return _asAX_rmSpace(str, ' '); } @@ -154,6 +158,30 @@ std::vector sstd::split(const std::string& str ){ retu std::vector sstd::split(const char* str, const char X){ return _asAX(str, X ); } std::vector sstd::split(const std::string& str, const char X){ return _asAX(str.c_str(), X ); } +std::vector _split_ss_base(const char* str, const uint str_len, const char* X, const uint X_len){ + if(str_len<=1){ return std::vector({str}); } + if(X_len ==0){ return std::vector({str}); } + if(X_len ==1){ return sstd::split(str, X[0]); } + + std::vector splitList; + std::string buf; + for(uint i=0; i sstd::split(const char* str, const char* X){ return _split_ss_base(str , ::strlen(str), X , ::strlen(X)); } +std::vector sstd::split(const std::string& str, const std::string& X){ return _split_ss_base(str.c_str(), str.size(), X.c_str(), X.size()); } + //--- std::vector sstd::split_rmSpace(const char* str ){ return _asAX_rmSpace(str, ' '); } @@ -163,36 +191,121 @@ std::vector sstd::split_rmSpace(const std::string& str, const char //----------------------------------------------------------------------------------------------------------------------------------------------- -bool sstd::split_quotes(std::vector& ret, const char* str, const char X){ - +bool sstd::split_quotes(std::vector& ret, const char* str){ bool is_escaped=false; bool in_d_quate=false; // double quate bool in_s_quate=false; // single quate std::string buf; - for(uint r=0; str[r]!='\0';){ // r: read place - buf.clear(); - for(; str[r]!='\0'; ++r){ - if(str[r]=='\\'){ is_escaped=true; buf+=str[r]; ++r; if(str[r]=='\0'){break;} } - - if(!is_escaped && !in_s_quate && str[r]=='"' ){ in_d_quate = !in_d_quate; } - if(!is_escaped && !in_d_quate && str[r]=='\''){ in_s_quate = !in_s_quate; } - - if(!in_d_quate && !in_s_quate && str[r]==X){ ++r; break; } - buf += str[r]; - - is_escaped=false; + uint i=0; + while(str[i]!='\0'){ if(str[i]==' '){++i;}else{break;} } // skip space + while(str[i]!='\0'){ // r: read place + if(str[i]=='\\'){ is_escaped=true; buf+=str[i]; ++i; if(str[i]=='\0'){break;} } + + if(!is_escaped && !in_s_quate && str[i]=='"' ){ in_d_quate = !in_d_quate; } + if(!is_escaped && !in_d_quate && str[i]=='\''){ in_s_quate = !in_s_quate; } + + if(!in_d_quate && !in_s_quate && str[i]==' '){ + ret.push_back(buf); buf.clear(); + ++i; + while(str[i]!='\0'){ if(str[i]==' '){++i;}else{break;} } // skip space + }else{ + buf += str[i]; + ++i; } - ret.push_back(std::move(buf)); + + is_escaped=false; } if(in_d_quate){ ret.clear(); return false; } if(in_s_quate){ ret.clear(); return false; } + if(buf.size()!=0){ ret.push_back(buf); } +// if(r==0 || (r>=1 && str[r-1]==X)){ ret.push_back(std::string()); } +// if(r>=1 && str[r-1]==X){ ret.push_back(std::string()); } return true; } +bool sstd::split_quotes(std::vector& ret, const std::string& str){ + return sstd::split_quotes(ret, str.c_str()); +} + +//--- + +bool sstd::split_quotes(std::vector& ret, const char* str, const char X){ + bool is_escaped=false; + bool in_d_quate=false; // double quate + bool in_s_quate=false; // single quate + std::string buf; + uint i=0; + // while(str[i]!='\0'){ if(str[i]==' '){++i;}else{break;} } // skip space + while(str[i]!='\0'){ // r: read place + if(str[i]=='\\'){ is_escaped=true; buf+=str[i]; ++i; if(str[i]=='\0'){break;} } + + if(!is_escaped && !in_s_quate && str[i]=='"' ){ in_d_quate = !in_d_quate; } + if(!is_escaped && !in_d_quate && str[i]=='\''){ in_s_quate = !in_s_quate; } + + if(!in_d_quate && !in_s_quate && str[i]==X){ + ret.push_back(buf); buf.clear(); + ++i; + // while(str[i]!='\0'){ if(str[i]==' '){++i;}else{break;} } // skip space + }else{ + buf += str[i]; + ++i; + } + + is_escaped=false; + } + if(in_d_quate){ ret.clear(); return false; } + if(in_s_quate){ ret.clear(); return false; } + if(buf.size()!=0){ ret.push_back(buf); } + // if(i==0 || (i>=1 && str[i-1]==X)){ ret.push_back(std::string()); } // compatible with Python split() + if(i>=1 && str[i-1]==X){ ret.push_back(std::string()); } + + return true; +} bool sstd::split_quotes(std::vector& ret, const std::string& str, const char X){ return sstd::split_quotes(ret, str.c_str(), X); } +//--- + +bool _split_quotes_base(std::vector& ret, const char* str, const uint str_len, const char* X, const uint X_len){ + bool is_escaped=false; + bool in_d_quate=false; // double quate + bool in_s_quate=false; // single quate + std::string buf; + uint i=0; + // while(str[i]!='\0'){ if(str[i]==' '){++i;}else{break;} } // skip space + while(i=str_len){break;} } + + if(!is_escaped && !in_s_quate && str[i]=='"' ){ in_d_quate = !in_d_quate; } + if(!is_escaped && !in_d_quate && str[i]=='\''){ in_s_quate = !in_s_quate; } + + if(!in_d_quate && !in_s_quate && sstd::startswith(&str[i], X)){ + ret.push_back(buf); buf.clear(); + i += X_len; + // while(str[i]!='\0'){ if(str[i]==' '){++i;}else{break;} } // skip space + }else{ + buf += str[i]; + ++i; + } + + is_escaped=false; + } + if(in_d_quate){ ret.clear(); return false; } + if(in_s_quate){ ret.clear(); return false; } + if(buf.size()!=0){ ret.push_back(buf); } + // if(i==0 || (i>=X_len && sstd::startswith(&str[i-X_len], X))){ ret.push_back(std::string()); } // compatible with Python split() + if(i>=X_len && sstd::startswith(&str[i-X_len], X)){ ret.push_back(std::string()); } + + return true; +} +bool sstd::split_quotes(std::vector& ret, const char* str, const char* X){ + return _split_quotes_base(ret, str, strlen(str), X, strlen(X)); +} +bool sstd::split_quotes(std::vector& ret, const std::string& str, const std::string& X){ + return _split_quotes_base(ret, str.c_str(), str.size(), X.c_str(), X.size()); +} + //----------------------------------------------------------------------------------------------------------------------------------------------- std::string lstrip_base(const uchar* str){ @@ -375,12 +488,7 @@ std::string stripAll_base(const char* str, const uint len, const char* stripList if(len * sLen <= 256){ for(uint i=0; i=0;){ + if(!sstd::charIn(str[r], stripList)){ break; } + --r; + } + }else{ + bool sTbl[256]={false}; + for(uint si=0; si=0;){ + if(! sTbl[ (uchar)str[r] ] ){ break; } + --r; + } + } + + str.resize(r+1); + return; +} +void sstd::rstripAll_ow( std::string& str, const char* stripList){ rstripAll_ow_base(str, stripList, strlen(stripList)); return; } +void sstd::rstripAll_ow( std::string& str, const std::string& stripList){ rstripAll_ow_base(str, stripList.c_str(), stripList.size()); return; } + void stripAll_ow_base(std::string& str, const char* stripList, const uint sLen){ const uint len = str.size(); uint r=0; if(len * sLen <= 256){ for(uint i=0; i split(const std::string& str); std::vector split(const char* str, const char X); std::vector split(const std::string& str, const char X); + std::vector split(const char* str, const char* X); + std::vector split(const std::string& str, const std::string& X); std::vector split_rmSpace(const char* str); // rm: remove std::vector split_rmSpace(const std::string& str); // rm: remove std::vector split_rmSpace(const char* str, const char X); // rm: remove std::vector split_rmSpace(const std::string& str, const char X); // rm: remove + bool split_quotes(std::vector& ret, const char* str); + bool split_quotes(std::vector& ret, const std::string& str); bool split_quotes(std::vector& ret, const char* str, const char X); bool split_quotes(std::vector& ret, const std::string& str, const char X); + bool split_quotes(std::vector& ret, const char* str, const char* X); + bool split_quotes(std::vector& ret, const std::string& str, const std::string& X); //--- @@ -69,6 +75,10 @@ namespace sstd{ std::string stripAll (const char* str, const std::string& stripList); std::string stripAll (const std::string& str, const std::string& stripList); + void lstripAll_ow( std::string& str, const char* stripList); + void lstripAll_ow( std::string& str, const std::string& stripList); + void rstripAll_ow( std::string& str, const char* stripList); + void rstripAll_ow( std::string& str, const std::string& stripList); void stripAll_ow( std::string& str, const char* stripList); void stripAll_ow( std::string& str, const std::string& stripList); // todo: rm '\t' diff --git a/sstd/src/string/strmatch.cpp b/sstd/src/string/strmatch.cpp index 08da9f76..553b441d 100755 --- a/sstd/src/string/strmatch.cpp +++ b/sstd/src/string/strmatch.cpp @@ -3,10 +3,27 @@ #include #include "./strmatch.hpp" -#include "../definitions/typeDef.h" +//----------------------------------------------------------------------------------------------------------------------------------------------- +// startswith() -//-------------------------------------------------------------------------------------------------------- +bool _startswith_base(const char* str, const char* searchString, const uint len){ + return ::strncmp(str, searchString, len)==0; // strncmp() is a standard function of the C Langage. +} +bool sstd::startswith(const char* str, const char* searchString){ return _startswith_base(str , searchString , ::strlen(searchString)); } +bool sstd::startswith(const char* str, const std::string& searchString){ return _startswith_base(str , searchString.c_str(), searchString.size() ); } +bool sstd::startswith(const std::string& str, const char* searchString){ return _startswith_base(str.c_str(), searchString , ::strlen(searchString)); } +bool sstd::startswith(const std::string& str, const std::string& searchString){ return _startswith_base(str.c_str(), searchString.c_str(), searchString.size() ); } + +//----------------------------------------------------------------------------------------------------------------------------------------------- +// strcmp() + +bool sstd::strcmp(const char* str1, const char* str2){ return (::strcmp(str1, str2 )==0); } +bool sstd::strcmp(const char* str1, const std::string& str2){ return (::strcmp(str1, str2.c_str())==0); } +bool sstd::strcmp(const std::string& str1, const char* str2){ return (::strcmp(str1.c_str(), str2 )==0); } +bool sstd::strcmp(const std::string& str1, const std::string& str2){ return (::strcmp(str1.c_str(), str2.c_str())==0); } + +//----------------------------------------------------------------------------------------------------------------------------------------------- // strmatch() bool sstd::strmatch( @@ -23,7 +40,7 @@ bool sstd::strmatch(const char* str, const std::string& wildcard){ return bool sstd::strmatch(const std::string& str, const char* wildcard){ return sstd::strmatch(str.c_str(), wildcard ); } bool sstd::strmatch(const std::string& str, const std::string& wildcard){ return sstd::strmatch(str.c_str(), wildcard.c_str()); } -//-------------------------------------------------------------------------------------------------------- +//----------------------------------------------------------------------------------------------------------------------------------------------- bool sstd::pathmatch( const char* str, // target string to search @@ -39,7 +56,7 @@ bool sstd::pathmatch(const char* str, const std::string& wildcard){ retur bool sstd::pathmatch(const std::string& str, const char* wildcard){ return sstd::pathmatch(str.c_str(), wildcard ); } bool sstd::pathmatch(const std::string& str, const std::string& wildcard){ return sstd::pathmatch(str.c_str(), wildcard.c_str()); } -//-------------------------------------------------------------------------------------------------------- +//----------------------------------------------------------------------------------------------------------------------------------------------- // strmatch_getWC() /* @@ -124,15 +141,44 @@ bool sstd::strmatch_getWC(const char* str, const std::string& wildcard, s bool sstd::strmatch_getWC(const std::string& str, const char* wildcard, std::string& retWC){ return sstd::strmatch_getWC(str.c_str(), wildcard , retWC); } bool sstd::strmatch_getWC(const std::string& str, const std::string& wildcard, std::string& retWC){ return sstd::strmatch_getWC(str.c_str(), wildcard.c_str(), retWC); } -//-------------------------------------------------------------------------------------------------------- -// strcmp() +//----------------------------------------------------------------------------------------------------------------------------------------------- +// rcount(), lcount(), count() -bool sstd::strcmp(const char* str1, const char* str2){ return (::strcmp(str1, str2 )==0); } -bool sstd::strcmp(const char* str1, const std::string& str2){ return (::strcmp(str1, str2.c_str())==0); } -bool sstd::strcmp(const std::string& str1, const char* str2){ return (::strcmp(str1.c_str(), str2 )==0); } -bool sstd::strcmp(const std::string& str1, const std::string& str2){ return (::strcmp(str1.c_str(), str2.c_str())==0); } +uint _rcount_base(const char* str, uint len, char X){ + uint ret_cnt=0; + for(int i=len-1; i>=0; --i){ + if(str[i]!=X){ break; } + ++ret_cnt; + } + return ret_cnt; +} +uint sstd::rcount(const char* str, char X){ return _rcount_base(str , ::strlen(str), X); } +uint sstd::rcount(const std::string& str, char X){ return _rcount_base(str.c_str(), str.size() , X); } + +//--- + +uint sstd::lcount(const char* str, char X){ + uint ret_cnt=0; + for(uint i=0; str[i]!='\0'; ++i){ + if(str[i]!=X){ break; } + ++ret_cnt; + } + return ret_cnt; +} +uint sstd::lcount(const std::string& str, char X){ return sstd::lcount(str.c_str(), X); } + +//--- -//-------------------------------------------------------------------------------------------------------- +uint sstd::count(const char* str, char X){ + uint ret_cnt=0; + for(uint i=0; str[i]!='\0'; ++i){ + if(str[i]==X){ ++ret_cnt; } + } + return ret_cnt; +} +uint sstd::count(const std::string& str, char X){ return sstd::count(str.c_str(), X); } + +//----------------------------------------------------------------------------------------------------------------------------------------------- #define return_isX(X) \ for(uint i=0; rhs[i]!='\0'; ++i){ \ @@ -155,7 +201,7 @@ bool sstd::isAlphabet_lower(const std::string& rhs){ return_isX( ('a'<=rhs[i] && #undef return_isX -//-------------------------------------------------------------------------------------------------------- +//----------------------------------------------------------------------------------------------------------------------------------------------- // charIn() bool sstd::charIn(const char lhs, const char* rhs){ // Is lhs in rhs ? @@ -197,24 +243,20 @@ bool sstd::charIn_all(const char* lhs, const std::string& rhs){ return ss bool sstd::charIn_all(const std::string& lhs, const char* rhs){ return sstd::charIn_all(lhs.c_str(), rhs ); } bool sstd::charIn_all(const std::string& lhs, const std::string& rhs){ return sstd::charIn_all(lhs.c_str(), rhs.c_str()); } -//-------------------------------------------------------------------------------------------------------- +//----------------------------------------------------------------------------------------------------------------------------------------------- // strIn() bool sstd::strIn(const char* lhs, const char* rhs){ // Is lhs in rhs ? - bool ret=true; - uint l=0, r=0; - for(;;){ - if(lhs[l]=='\0'){ return ret; } - if(rhs[r]=='\0'){ return false; } - - if(lhs[l]==rhs[r]){ ++l; ret=true; - } else { l=0; ret=false; } - - ++r; + if(lhs[0]=='\0'){ return true; } + + uint r=0; + for(; rhs[r]!='\0'; ++r){ + if(sstd::startswith(&rhs[r], lhs)){ return true; } } + return false; } bool sstd::strIn(const char* lhs, const std::string& rhs){ return sstd::strIn(lhs , rhs.c_str()); } bool sstd::strIn(const std::string& lhs, const char* rhs){ return sstd::strIn(lhs.c_str(), rhs ); } bool sstd::strIn(const std::string& lhs, const std::string& rhs){ return sstd::strIn(lhs.c_str(), rhs.c_str()); } -//-------------------------------------------------------------------------------------------------------- +//----------------------------------------------------------------------------------------------------------------------------------------------- diff --git a/sstd/src/string/strmatch.hpp b/sstd/src/string/strmatch.hpp index 8a4d27c2..3eed7355 100755 --- a/sstd/src/string/strmatch.hpp +++ b/sstd/src/string/strmatch.hpp @@ -1,7 +1,13 @@ #pragma once #include +#include "../definitions/typeDef.h" namespace sstd{ + bool startswith(const char* str, const char* searchString); + bool startswith(const char* str, const std::string& searchString); + bool startswith(const std::string& str, const char* searchString); + bool startswith(const std::string& str, const std::string& searchString); + bool strcmp(const char* str1, const char* str2); bool strcmp(const char* str1, const std::string& str2); bool strcmp(const std::string& str1, const char* str2); @@ -26,6 +32,13 @@ namespace sstd{ bool strmatch_getWC(const std::string& str, const char* wildcard, std::string& retWC); bool strmatch_getWC(const std::string& str, const std::string& wildcard, std::string& retWC); + uint rcount(const char* str, char X); + uint rcount(const std::string& str, char X); + uint lcount(const char* str, char X); + uint lcount(const std::string& str, char X); + uint count(const char* str, char X); + uint count(const std::string& str, char X); + bool isNum (const char rhs); bool isNum (const char* rhs); bool isNum (const std::string& rhs); diff --git a/test/src_test/file/yaml.cpp b/test/src_test/file/yaml.cpp index 3b8d1c2d..893bb755 100644 --- a/test/src_test/file/yaml.cpp +++ b/test/src_test/file/yaml.cpp @@ -2,9 +2,956 @@ #include "../../gtest_parallel/test_main.hpp" //----------------------------------------------------------------------------------------------------------------------------------------------- -// var +// tests of sub-functions -TEST(yaml, var_str_1_line){ +TEST(yaml, _split_quotes_by_control_chars_01){ + std::vector ret; + const char* str = " [ a, b , c , { k1:v1, k 2 : v 2 , k3:}] "; + bool tf = sstd_yaml::_split_quotes_by_control_chars(ret, str, strlen(str)); // TEST THIS LINE + +// sstd::printn(tf); +// sstd::printn(ret); + + std::vector ret_ans = {"[", "a", ",", "b", ",", "c", ",", "{", "k1", ":", "v1", ",", "k 2", ":", "v 2", ",", "k3", ":", "}", "]"}; + ASSERT_TRUE(tf); + ASSERT_TRUE(ret == ret_ans); +} +TEST(yaml, _split_quotes_by_control_chars_02){ + std::vector ret; + const char* str = " \" [ \", ' [ ] {} ' , a, b , c , { k1:v1, k 2 : v 2 , k3:}] "; + bool tf = sstd_yaml::_split_quotes_by_control_chars(ret, str, strlen(str)); // TEST THIS LINE + +// sstd::printn(tf); +// sstd::printn(ret); + + std::vector ret_ans = {"\" [ \"", ",", "' [ ] {} '", ",", "a", ",", "b", ",", "c", ",", "{", "k1", ":", "v1", ",", "k 2", ":", "v 2", ",", "k3", ":", "}", "]"}; + ASSERT_TRUE(tf); + ASSERT_TRUE(ret == ret_ans); +} + +//--- + +// All the Test Cases of "sstd_yaml::_data_type_and_format()" +// +// ┌───────────┬────────────┬────────┬────────────────────┬────────────────────┬─────────┬────────────────────────────────────────┬────────────────────────────────────────────────┐ +// │ │ │ │ (Black Style Side) │ (Black Style Side) │ │ Concrete Example │ │ +// │ Test Case │ Input │ Is Str │ Is List │ Is Hash │ Is Flow │ 01 02 │ Note │ +// ├───────────┼────────────┼────────┼────────────────────┼────────────────────┼─────────┼────────────┼───────────────────────────┼────────────────────────────────────────────────┤ +// │ Case01 │ v │ T │ │ │ │ v │ "k: v" │ Default value │ +// ├───────────┼────────────┼────────┼────────────────────┼────────────────────┼─────────┼────────────┼───────────────────────────┼────────────────────────────────────────────────┤ +// │ Case02 │ - v │ │ T │ │ │ - v │ - - - "k: v" │ │ +// ├───────────┼────────────┼────────┼────────────────────┼────────────────────┼─────────┼────────────┼───────────────────────────┼────────────────────────────────────────────────┤ +// │ Case03 │ k: v │ │ │ T │ │ k: v │ "k[]{: }": "v[]{: }" │ │ +// ├───────────┼────────────┼────────┼────────────────────┼────────────────────┼─────────┼────────────┼───────────────────────────┼────────────────────────────────────────────────┤ +// │ Case04 │ k[]: v[] │ │ │ T │ │ k[]: v[] │ k[:]: v[:] │ │ +// ├───────────┼────────────┼────────┼────────────────────┼────────────────────┼─────────┼────────────┼───────────────────────────┼────────────────────────────────────────────────┤ +// │ Case05 │ k{}: v{} │ │ │ T │ │ k{}: v{} │ k{:}: v{:} │ │ +// ├───────────┼────────────┼────────┼────────────────────┼────────────────────┼─────────┼────────────┼───────────────────────────┼────────────────────────────────────────────────┤ +// │ Case06 │ [] │ T │ │ │ T │ [] │ ["[]{}: "] │ IsStr become `true` because of a default value │ +// ├───────────┼────────────┼────────┼────────────────────┼────────────────────┼─────────┼────────────┼───────────────────────────┼────────────────────────────────────────────────┤ +// │ Case07 │ {} │ T │ │ │ T │ {} │ {"[]{}: ": "[]{}: "} │ IsStr become `true` because of a default value │ +// ├───────────┼────────────┼────────┼────────────────────┼────────────────────┼─────────┼────────────┼───────────────────────────┼────────────────────────────────────────────────┤ +// │ Case08 │ - [] │ │ T │ │ T │ - [] │ - ["[]{}: "] │ │ +// ├───────────┼────────────┼────────┼────────────────────┼────────────────────┼─────────┼────────────┼───────────────────────────┼────────────────────────────────────────────────┤ +// │ Case09 │ - {} │ │ T │ │ T │ - {} │ - {"[]{}: ": "[]{}: "} │ │ +// ├───────────┼────────────┼────────┼────────────────────┼────────────────────┼─────────┼────────────┼───────────────────────────┼────────────────────────────────────────────────┤ +// │ Case10 │ - k: v │ │ T │ T │ │ - k: v │ - "k[]{: }": "v[]{: }" │ │ +// ├───────────┼────────────┼────────┼────────────────────┼────────────────────┼─────────┼────────────┼───────────────────────────┼────────────────────────────────────────────────┤ +// │ Case11 │ - k[]: v[] │ │ T │ T │ │ - k[]: v[] │ - k [:]: v[:] │ │ +// ├───────────┼────────────┼────────┼────────────────────┼────────────────────┼─────────┼────────────┼───────────────────────────┼────────────────────────────────────────────────┤ +// │ Case12 │ - k{}: v{} │ │ T │ T │ │ - k{}: v{} │ - k {:}: v{:} │ │ +// ├───────────┼────────────┼────────┼────────────────────┼────────────────────┼─────────┼────────────┼───────────────────────────┼────────────────────────────────────────────────┤ +// │ Case13 │ k: [] │ │ │ T │ T │ k: [] │ k: ["[]{}: "] │ │ +// ├───────────┼────────────┼────────┼────────────────────┼────────────────────┼─────────┼────────────┼───────────────────────────┼────────────────────────────────────────────────┤ +// │ Case14 │ k: {} │ │ │ T │ T │ k: {} │ k: {"[]{}: ": "[]{}: "} │ │ +// ├───────────┼────────────┼────────┼────────────────────┼────────────────────┼─────────┼────────────┼───────────────────────────┼────────────────────────────────────────────────┤ +// │ Case15 │ - k: [] │ │ T │ T │ T │ - k: [] │ - k: ["[]{}: "] │ │ +// ├───────────┼────────────┼────────┼────────────────────┼────────────────────┼─────────┼────────────┼───────────────────────────┼────────────────────────────────────────────────┤ +// │ Case16 │ - k: {} │ │ T │ T │ T │ - k: {} │ - k: {"[]{}: ": "[]{}: "} │ │ +// └───────────┴────────────┴────────┴────────────────────┴────────────────────┴─────────┴────────────┴───────────────────────────┴────────────────────────────────────────────────┘ + +//--- +// Test _str2token() of data type and format + +#define TEST_STR2TOKEN__DATA_TYPE_AND_FORMAT(IS_LIST, IS_HASH, IS_FLOW, LIST_TYPE_COUNT, S_IN) \ + std::string s = S_IN; \ + std::vector v_ret; \ + bool ret = sstd_yaml::_str2token(v_ret, s); \ + ASSERT_TRUE(ret); \ + ASSERT_EQ((uint)v_ret.size(), (uint)1); \ + \ + uint ans_type=sstd_yaml::num_str; \ + if(IS_LIST){ ans_type += sstd_yaml::num_list; } \ + if(IS_HASH){ ans_type += sstd_yaml::num_hash; } \ + ASSERT_EQ(v_ret[0].type, (uint)ans_type); \ + \ + uint ans_flow = IS_FLOW ? sstd_yaml::num_flow_style_base : sstd_yaml::num_block_style_base; \ + ASSERT_EQ(v_ret[0].format, (uint)ans_flow); \ + ASSERT_EQ(v_ret[0].list_type_cnt, (uint)LIST_TYPE_COUNT); + +TEST(yaml, _str2token__data_type_and_format_case01_01){ TEST_STR2TOKEN__DATA_TYPE_AND_FORMAT(false, false, false, 0, "v" ); } +TEST(yaml, _str2token__data_type_and_format_case02_01){ TEST_STR2TOKEN__DATA_TYPE_AND_FORMAT( true, false, false, 1, "- v" ); } +TEST(yaml, _str2token__data_type_and_format_case03_01){ TEST_STR2TOKEN__DATA_TYPE_AND_FORMAT(false, true, false, 0, "k: v" ); } +TEST(yaml, _str2token__data_type_and_format_case04_01){ TEST_STR2TOKEN__DATA_TYPE_AND_FORMAT(false, true, false, 0, "k[]: v[]" ); } +TEST(yaml, _str2token__data_type_and_format_case05_01){ TEST_STR2TOKEN__DATA_TYPE_AND_FORMAT(false, true, false, 0, "k{}: v{}" ); } +TEST(yaml, _str2token__data_type_and_format_case06_01){ TEST_STR2TOKEN__DATA_TYPE_AND_FORMAT(false, false, true, 0, "[]" ); } +TEST(yaml, _str2token__data_type_and_format_case07_01){ TEST_STR2TOKEN__DATA_TYPE_AND_FORMAT(false, false, true, 0, "{}" ); } +TEST(yaml, _str2token__data_type_and_format_case08_01){ TEST_STR2TOKEN__DATA_TYPE_AND_FORMAT( true, false, true, 1, "- []" ); } +TEST(yaml, _str2token__data_type_and_format_case09_01){ TEST_STR2TOKEN__DATA_TYPE_AND_FORMAT( true, false, true, 1, "- {}" ); } +TEST(yaml, _str2token__data_type_and_format_case10_01){ TEST_STR2TOKEN__DATA_TYPE_AND_FORMAT( true, true, false, 1, "- k: v" ); } +TEST(yaml, _str2token__data_type_and_format_case11_01){ TEST_STR2TOKEN__DATA_TYPE_AND_FORMAT( true, true, false, 1, "- k[]: v[]"); } +TEST(yaml, _str2token__data_type_and_format_case12_01){ TEST_STR2TOKEN__DATA_TYPE_AND_FORMAT( true, true, false, 1, "- k{}: v{}"); } +TEST(yaml, _str2token__data_type_and_format_case13_01){ TEST_STR2TOKEN__DATA_TYPE_AND_FORMAT(false, true, true, 0, "k: []" ); } +TEST(yaml, _str2token__data_type_and_format_case14_01){ TEST_STR2TOKEN__DATA_TYPE_AND_FORMAT(false, true, true, 0, "k: {}" ); } +TEST(yaml, _str2token__data_type_and_format_case15_01){ TEST_STR2TOKEN__DATA_TYPE_AND_FORMAT( true, true, true, 1, "- k: []" ); } +TEST(yaml, _str2token__data_type_and_format_case16_01){ TEST_STR2TOKEN__DATA_TYPE_AND_FORMAT( true, true, true, 1, "- k: {}" ); } + +//TEST(yaml, _str2token__data_type_and_format_case02_02){ TEST_STR2TOKEN__DATA_TYPE_AND_FORMAT( true, false, false, 3, "- - - v" ); } // 個別にテストケースを書く +TEST(yaml, _str2token__data_type_and_format_case03_02){ TEST_STR2TOKEN__DATA_TYPE_AND_FORMAT(false, true, false, 0, "k : v" ); } +TEST(yaml, _str2token__data_type_and_format_case04_02){ TEST_STR2TOKEN__DATA_TYPE_AND_FORMAT(false, true, false, 0, "k[: v[" ); } +TEST(yaml, _str2token__data_type_and_format_case04_03){ TEST_STR2TOKEN__DATA_TYPE_AND_FORMAT(false, true, false, 0, "k [: v [" ); } +TEST(yaml, _str2token__data_type_and_format_case05_02){ TEST_STR2TOKEN__DATA_TYPE_AND_FORMAT(false, true, false, 0, "k{: v{" ); } +TEST(yaml, _str2token__data_type_and_format_case05_03){ TEST_STR2TOKEN__DATA_TYPE_AND_FORMAT(false, true, false, 0, "k {: v {" ); } +TEST(yaml, _str2token__data_type_and_format_case06_02){ TEST_STR2TOKEN__DATA_TYPE_AND_FORMAT(false, false, true, 0, "[{: }]" ); } // Ex: [a, b, c, {k: v}] + +//--- +// Test _str2token() of val1 and val2 + +#define TEST_STR2TOKEN__KEY_VAL(KEY, VAL, S_IN) \ + std::string s = S_IN; \ + std::vector v_ret; \ + bool ret = sstd_yaml::_str2token(v_ret, s); \ + ASSERT_TRUE(ret); \ + ASSERT_EQ(v_ret.size(), (uint)1); \ + ASSERT_STREQ(v_ret[0].key.c_str(), KEY); \ + ASSERT_STREQ(v_ret[0].val.c_str(), VAL); + +TEST(yaml, _str2token_val1_val2_list ){ TEST_STR2TOKEN__KEY_VAL("", "a", "- a"); } +TEST(yaml, _str2token_val1_val2_list_02 ){ TEST_STR2TOKEN__KEY_VAL("", "a ,", "- a ,"); } +TEST(yaml, _str2token_val1_val2_list_hash ){ TEST_STR2TOKEN__KEY_VAL("k", "v", "k: v"); } +TEST(yaml, _str2token_val1_val2_list_hash_02 ){ TEST_STR2TOKEN__KEY_VAL("k ,", "v ,", "- k , : v ,"); } +TEST(yaml, _str2token_val1_val2_list_hash_space ){ TEST_STR2TOKEN__KEY_VAL("k {", "v {", "- k { : v { "); } +TEST(yaml, _str2token_val1_val2_flow ){ TEST_STR2TOKEN__KEY_VAL("", "[{k: v}]", "[{k: v}]"); } + +// mutliline flow stype notation +TEST(yaml, _str2token_val1_val2_multiline_flow ){ TEST_STR2TOKEN__KEY_VAL("", "[\na,\nb,\nc\n]", "[\na,\nb,\nc\n]"); } +TEST(yaml, _str2token_val1_val2_multiline_flow_list ){ TEST_STR2TOKEN__KEY_VAL("", "[\na,\nb,\nc\n]", "- [\na,\nb,\nc\n]"); } +TEST(yaml, _str2token_val1_val2_multiline_flow_hash ){ TEST_STR2TOKEN__KEY_VAL("k", "[\na,\nb,\nc\n]", "k: [\na,\nb,\nc\n]"); } +TEST(yaml, _str2token_val1_val2_multiline_flow_list_hash){ TEST_STR2TOKEN__KEY_VAL("k", "[\na,\nb,\nc\n]", "- k: [\na,\nb,\nc\n]"); } + +//--- +// Test _str2token() of remove comments +//* +// remove comments +//TEST(yaml, _str2token_rm_comment_case01){ TEST_STR2TOKEN__KEY_VAL("", "a", "a\n# b"); } // あとで直す +TEST(yaml, _str2token_rm_comment_case02){ TEST_STR2TOKEN__KEY_VAL("", "a", "a # comment"); } +TEST(yaml, _str2token_rm_comment_case03){ TEST_STR2TOKEN__KEY_VAL("", "a # comment", "\"a # comment\""); } +//TEST(yaml, _str2token_rm_comment_case04){ TEST_STR2TOKEN__KEY_VAL("", "|\na\nb\nc", "- |\na # comment\nb # comment\nc # comment"); } // あとで直す +//*/ +//--- +//* +TEST(yaml, _str2token_multi_list_case00){ + std::string s = R"( +k_X: + k1: |+ + a + + c + +k_Y: v_Y +)"; + std::vector v_ret; + bool ret = sstd_yaml::_str2token(v_ret, s); +// sstd::printn(v_ret.size()); +// sstd::printn(v_ret); + + ASSERT_TRUE(ret); + ASSERT_EQ(v_ret.size(), (uint)3); + ASSERT_STREQ(v_ret[0].rawStr.c_str(), "k_X: "); + ASSERT_STREQ(v_ret[0].val.c_str(), "" ); + ASSERT_STREQ(v_ret[1].rawStr.c_str(), " k1: |+\n a\n \n c\n "); + ASSERT_STREQ(v_ret[1].key.c_str(), "k1" ); + ASSERT_STREQ(v_ret[1].val.c_str(), "a\n\nc\n\n"); // "|+\n a\n \n c\n " + ASSERT_STREQ(v_ret[2].rawStr.c_str(), "k_Y: v_Y"); + ASSERT_STREQ(v_ret[2].key.c_str(), "k_Y"); + ASSERT_STREQ(v_ret[2].val.c_str(), "v_Y"); +} + +//--- + +TEST(yaml, _str2token_multi_list_case01){ + std::string s = "- a\n- b\n- c"; + std::vector v_ret; + bool ret = sstd_yaml::_str2token(v_ret, s); +// sstd::printn(v_ret); + + ASSERT_TRUE(ret); + ASSERT_EQ(v_ret.size(), (uint)3); + ASSERT_STREQ(v_ret[0].rawStr.c_str(), "- a"); + ASSERT_STREQ(v_ret[0].val.c_str(), "a" ); + ASSERT_STREQ(v_ret[1].rawStr.c_str(), "- b"); + ASSERT_STREQ(v_ret[1].val.c_str(), "b" ); + ASSERT_STREQ(v_ret[2].rawStr.c_str(), "- c"); + ASSERT_STREQ(v_ret[2].val.c_str(), "c"); +} +TEST(yaml, _str2token_multi_list_case02){ + std::string s = "- \"\"\n- \"\"\n- \"\""; + std::vector v_ret; + bool ret = sstd_yaml::_str2token(v_ret, s); +// sstd::printn(v_ret); + + ASSERT_TRUE(ret); + ASSERT_EQ(v_ret.size(), (uint)3); + ASSERT_STREQ(v_ret[0].rawStr.c_str(), "- \"\""); + ASSERT_STREQ(v_ret[0].val.c_str(), ""); + ASSERT_STREQ(v_ret[1].rawStr.c_str(), "- \"\""); + ASSERT_STREQ(v_ret[1].val.c_str(), ""); + ASSERT_STREQ(v_ret[2].rawStr.c_str(), "- \"\""); + ASSERT_STREQ(v_ret[2].val.c_str(), ""); +} +TEST(yaml, _str2token_multi_list_case03){ + std::string s = "-\n - a"; + std::vector v_ret; + bool ret = sstd_yaml::_str2token(v_ret, s); +// sstd::printn(v_ret); + + ASSERT_TRUE(ret); + ASSERT_EQ(v_ret.size(), (uint)2); + ASSERT_STREQ(v_ret[0].rawStr.c_str(), "-"); + ASSERT_STREQ(v_ret[0].val.c_str(), ""); + ASSERT_STREQ(v_ret[1].rawStr.c_str(), " - a"); + ASSERT_STREQ(v_ret[1].val.c_str(), "a"); +} +TEST(yaml, _str2token_multi_list_case04){ + std::string s = "- \n - a"; + std::vector v_ret; + bool ret = sstd_yaml::_str2token(v_ret, s); +// sstd::printn(v_ret); + + ASSERT_TRUE(ret); + ASSERT_EQ(v_ret.size(), (uint)2); + ASSERT_STREQ(v_ret[0].rawStr.c_str(), "- "); + ASSERT_STREQ(v_ret[0].val.c_str(), ""); + ASSERT_STREQ(v_ret[1].rawStr.c_str(), " - a"); + ASSERT_STREQ(v_ret[1].val.c_str(), "a"); +} + +//--- + +TEST(yaml, _str2token_multi_list_case05){ + std::string s = "- [{\nk11: v11,\nk12:v12,\nk13:v13\n}]\n- [{\nk21: v21,\nk22:v22,\nk23:v23\n}]"; + std::vector v_ret; + bool ret = sstd_yaml::_str2token(v_ret, s); +// sstd::printn(v_ret); + + ASSERT_TRUE(ret); + ASSERT_EQ(v_ret.size(), (uint)2); + ASSERT_STREQ(v_ret[0].rawStr.c_str(), "- [{\nk11: v11,\nk12:v12,\nk13:v13\n}]"); + ASSERT_STREQ(v_ret[0].val.c_str(), "[{\nk11: v11,\nk12:v12,\nk13:v13\n}]"); + ASSERT_STREQ(v_ret[1].rawStr.c_str(), "- [{\nk21: v21,\nk22:v22,\nk23:v23\n}]"); + ASSERT_STREQ(v_ret[1].val.c_str(), "[{\nk21: v21,\nk22:v22,\nk23:v23\n}]"); +} + +//--- + +TEST(yaml, _str2token_multi_list_case06){ + std::string s = "- - - a"; + std::vector v_ret; + bool ret = sstd_yaml::_str2token(v_ret, s); +// sstd::printn(v_ret); + + ASSERT_TRUE(ret); + ASSERT_EQ(v_ret.size(), (uint)3); + ASSERT_STREQ(v_ret[0].rawStr.c_str(), "- - - a"); + ASSERT_STREQ(v_ret[0].val.c_str(), ""); + ASSERT_STREQ(v_ret[1].val.c_str(), ""); + ASSERT_STREQ(v_ret[2].val.c_str(), "a"); + ASSERT_EQ(v_ret[0].list_type_cnt, (uint)1); + ASSERT_EQ(v_ret[1].list_type_cnt, (uint)1); + ASSERT_EQ(v_ret[2].list_type_cnt, (uint)1); +} + +//--- + +TEST(yaml, _str2token_multi_list_case07){ + std::string s=R"( +- a # comment +- | + b1 + b2 + b3 + +- c +- d +)"; + std::vector v_ret; + bool ret = sstd_yaml::_str2token(v_ret, s); +// sstd::printn(v_ret); + + ASSERT_TRUE(ret); + ASSERT_EQ(v_ret.size(), (uint)4); + ASSERT_STREQ(v_ret[0].rawStr.c_str(), "- a # comment"); + ASSERT_STREQ(v_ret[0].val.c_str(), "a"); +// sstd::printn(v_ret[1].rawStr.c_str()); + ASSERT_STREQ(v_ret[1].rawStr.c_str(), R"(- | + b1 + b2 + b3 +)"); +// sstd::printn(v_ret[1].val.c_str()); + ASSERT_STREQ(v_ret[1].val.c_str(), "b1\nb2\nb3\n"); // "|\n b1\n b2\n b3\n" +} +TEST(yaml, _str2token_multi_list_case08){ + std::string s=R"( +- a # comment +- k: |+ + b1 + b2 + b3 + +- c +- d +)"; + std::vector v_ret; + bool ret = sstd_yaml::_str2token(v_ret, s); +// sstd::printn(v_ret); + + ASSERT_TRUE(ret); + ASSERT_EQ(v_ret.size(), (uint)4); + ASSERT_STREQ(v_ret[0].rawStr.c_str(), "- a # comment"); + ASSERT_STREQ(v_ret[0].val.c_str(), "a"); +// sstd::printn(v_ret[1].rawStr.c_str()); + ASSERT_STREQ(v_ret[1].rawStr.c_str(), R"(- k: |+ + b1 + b2 + b3 +)"); +// sstd::printn(v_ret[1].val.c_str()); +// sstd::printn(v_ret[1].val.c_str()); + ASSERT_STREQ(v_ret[1].key.c_str(), "k"); + ASSERT_STREQ(v_ret[1].val.c_str(), "b1\nb2\nb3\n\n"); // "|+\n b1\n b2\n b3\n" +} +TEST(yaml, _str2token_multi_list_case09){ + std::string s=R"( +- a # comment +- k:| + b1 + b2 + b3 + +- c +- d +)"; + std::vector v_ret; + bool ret = sstd_yaml::_str2token(v_ret, s); +// sstd::printn(v_ret); + + ASSERT_TRUE(ret); + ASSERT_EQ(v_ret.size(), (uint)4); +// sstd::printn(v_ret[0].val.c_str()); + ASSERT_STREQ(v_ret[0].val.c_str(), "a"); +// sstd::printn(v_ret[1].rawStr.c_str()); + ASSERT_STREQ(v_ret[1].rawStr.c_str(), R"(- k:| + b1 + b2 + b3 +)"); +// sstd::printn(v_ret[1].val.c_str()); + ASSERT_STREQ(v_ret[1].val.c_str(), "k:| b1 b2 b3"); // "k:|\n b1\n b2\n b3\n" + ASSERT_STREQ(v_ret[2].val.c_str(), "c"); + ASSERT_STREQ(v_ret[3].val.c_str(), "d"); +} +TEST(yaml, _str2token_multi_list_case10){ + std::string s=R"( +- a + - a +)"; + std::vector v_ret; + bool ret = sstd_yaml::_str2token(v_ret, s); +// sstd::printn(v_ret); + + ASSERT_TRUE(ret); + ASSERT_EQ(v_ret.size(), (uint)1); +// sstd::printn(v_ret[0].rawStr.c_str()); +// ASSERT_STREQ(v_ret[0].rawStr.c_str(), R"()"); +// sstd::printn(v_ret[0].val.c_str()); + ASSERT_STREQ(v_ret[0].val.c_str(), "a - a"); // "a\n - a" +} + +//--- + +//TEST(yaml, _str2token_multi_list_except_pipe_or_inequality_sign_case01){ +//} +//*/ +//----------------------------------------------------------------------------------------------------------------------------------------------- +// Test _format_mult_line_str() +//* +TEST(yaml, _format_mult_line_str__pipeSymbol__last_line_breaks_case01){ // '|' + std::string s=R"(| + a)"; + std::string ret; + const uint hsc_base_yaml=0; + const bool has_next_token = false; + bool ret_TF = sstd_yaml::_format_mult_line_str(ret, s, hsc_base_yaml, has_next_token); + //sstd::printn(ret_TF); + //sstd::printn(ret); + + ASSERT_TRUE(ret_TF); + ASSERT_STREQ(ret.c_str(), "a"); +} +TEST(yaml, _format_mult_line_str__pipeSymbol__last_line_breaks_case02){ // '|' + std::string s=R"(| + a +)"; + std::string ret; + const uint hsc_base_yaml=0; + const bool has_next_token = false; + bool ret_TF = sstd_yaml::_format_mult_line_str(ret, s, hsc_base_yaml, has_next_token); + //sstd::printn(ret_TF); + //sstd::printn(ret); + + ASSERT_TRUE(ret_TF); + ASSERT_STREQ(ret.c_str(), "a\n"); +} +TEST(yaml, _format_mult_line_str__pipeSymbol__last_line_breaks_case03){ // '|' + std::string s=R"(| + a + +)"; + std::string ret; + const uint hsc_base_yaml=0; + const bool has_next_token = false; + bool ret_TF = sstd_yaml::_format_mult_line_str(ret, s, hsc_base_yaml, has_next_token); + //sstd::printn(ret_TF); + //sstd::printn(ret); + + ASSERT_TRUE(ret_TF); + ASSERT_STREQ(ret.c_str(), "a\n"); +} +TEST(yaml, _format_mult_line_str__pipeSymbol__last_line_breaks_case04){ // '|+' + std::string s=R"(|+ + a)"; + std::string ret; + const uint hsc_base_yaml=0; + const bool has_next_token = false; + bool ret_TF = sstd_yaml::_format_mult_line_str(ret, s, hsc_base_yaml, has_next_token); + //sstd::printn(ret_TF); + //sstd::printn(ret); + + ASSERT_TRUE(ret_TF); + ASSERT_STREQ(ret.c_str(), "a"); +} +TEST(yaml, _format_mult_line_str__pipeSymbol__last_line_breaks_case05){ // '|+' + std::string s=R"(|+ + a +)"; + std::string ret; + const uint hsc_base_yaml=0; + const bool has_next_token = false; + bool ret_TF = sstd_yaml::_format_mult_line_str(ret, s, hsc_base_yaml, has_next_token); + //sstd::printn(ret_TF); + //sstd::printn(ret); + + ASSERT_TRUE(ret_TF); + ASSERT_STREQ(ret.c_str(), "a\n"); +} +TEST(yaml, _format_mult_line_str__pipeSymbol__last_line_breaks_case06){ // '|+' + std::string s=R"(|+ + a + +)"; + std::string ret; + const uint hsc_base_yaml=0; + const bool has_next_token = false; + bool ret_TF = sstd_yaml::_format_mult_line_str(ret, s, hsc_base_yaml, has_next_token); + //sstd::printn(ret_TF); + //sstd::printn(ret); + + ASSERT_TRUE(ret_TF); + ASSERT_STREQ(ret.c_str(), "a\n\n"); +} + +//--- + +TEST(yaml, _format_mult_line_str__pipeSymbol__NoPlusOrMinus__case01){ // '|1' + std::string s=R"(|1 + b1 + b2 + b3 + + b4 + +)"; + std::string ret; + const uint hsc_base_yaml=0; + const bool has_next_token = false; + bool ret_TF = sstd_yaml::_format_mult_line_str(ret, s, hsc_base_yaml, has_next_token); +// sstd::printn(ret_TF); +// sstd::printn(ret); + + ASSERT_TRUE(ret_TF); + ASSERT_STREQ(ret.c_str(), R"( b1 +b2 +b3 + +b4 +)"); +} +TEST(yaml, _format_mult_line_str__pipeSymbol__PipeSymbol__case01){ // '|+1' + std::string s=R"(|+1 + b1 + b2 + b3 + + b4 + +)"; + std::string ret; + const uint hsc_base_yaml=0; + const bool has_next_token = false; + bool ret_TF = sstd_yaml::_format_mult_line_str(ret, s, hsc_base_yaml, has_next_token); +// sstd::printn(ret_TF); +// sstd::printn(ret); + + ASSERT_TRUE(ret_TF); + ASSERT_STREQ(ret.c_str(), R"( b1 +b2 +b3 + +b4 + +)"); +} +TEST(yaml, _format_mult_line_str__pipeSymbol__MinusSymbol__case01){ // '|-1' + std::string s=R"(|-1 + b1 + b2 + b3 + + b4 + +)"; + std::string ret; + const uint hsc_base_yaml=0; + const bool has_next_token = false; + bool ret_TF = sstd_yaml::_format_mult_line_str(ret, s, hsc_base_yaml, has_next_token); +// sstd::printn(ret_TF); +// sstd::printn(ret); + + ASSERT_TRUE(ret_TF); + ASSERT_STREQ(ret.c_str(), R"( b1 +b2 +b3 + +b4)"); +} + +//--- + +TEST(yaml, _format_mult_line_str__GreaterThanSymbol__NoPlusOrMinus__case01){ // '>1' + std::string s=R"(>1 + b1 + b2 + b3)"; + std::string ret; + const uint hsc_base_yaml=0; + const bool has_next_token = false; + bool ret_TF = sstd_yaml::_format_mult_line_str(ret, s, hsc_base_yaml, has_next_token); +// sstd::printn(ret_TF); +// sstd::printn(ret); + + ASSERT_TRUE(ret_TF); + ASSERT_STREQ(ret.c_str(), " b1\n b2\n b3"); +} +TEST(yaml, _format_mult_line_str__GreaterThanSymbol__NoPlusOrMinus__case02){ // '>1' + std::string s=R"(>1 + b1 + b2 + b3)"; + std::string ret; + const uint hsc_base_yaml=0; + const bool has_next_token = false; + bool ret_TF = sstd_yaml::_format_mult_line_str(ret, s, hsc_base_yaml, has_next_token); +// sstd::printn(ret_TF); +// sstd::printn(ret); + + ASSERT_TRUE(ret_TF); + ASSERT_STREQ(ret.c_str(), "b1 b2 b3"); +} +TEST(yaml, _format_mult_line_str__GreaterThanSymbol__NoPlusOrMinus__case03){ // '>1' + std::string s=R"(>1 + b1 + b2 + b3 + b4)"; + std::string ret; + const uint hsc_base_yaml=0; + const bool has_next_token = false; + bool ret_TF = sstd_yaml::_format_mult_line_str(ret, s, hsc_base_yaml, has_next_token); +// sstd::printn(ret_TF); +// sstd::printn(ret); + + ASSERT_TRUE(ret_TF); + //ASSERT_STREQ(ret.c_str(), "b1\n b2\nb3 b4"); + ASSERT_STREQ(ret.c_str(), "b1\n b2\nb3 b4"); +} +TEST(yaml, _format_mult_line_str__GreaterThanSymbol__NoPlusOrMinus__case04){ // '>1' + std::string s=R"(>1 + b1 + b2 + b3 + +)"; + std::string ret; + const uint hsc_base_yaml=2; + const bool has_next_token = false; + bool ret_TF = sstd_yaml::_format_mult_line_str(ret, s, hsc_base_yaml, has_next_token); +// sstd::printn(ret_TF); +// sstd::printn(ret); + + ASSERT_TRUE(ret_TF); + ASSERT_STREQ(ret.c_str(), " b1\n b2\n b3\n"); +} + +//--- + +TEST(yaml, _format_mult_line_str__NoSymbol__case01){ + std::string s=R"(k:|x + a + b +)"; + std::string ret; + const uint hsc_base_yaml=0; + const bool has_next_token = false; + bool ret_TF = sstd_yaml::_format_mult_line_str(ret, s, hsc_base_yaml, has_next_token); +// sstd::printn(ret_TF); +// sstd::printn(ret); + + ASSERT_TRUE(ret_TF); + ASSERT_STREQ(ret.c_str(), "k:|x a b"); +} +//*/ +//----------------------------------------------------------------------------------------------------------------------------------------------- +//* +TEST(yaml, _token2cmd_usual_cases){ + std::string s = R"( +- k1: v11 +- k2: + - v21 + - v22 + - k23: # null + - k24: v241 +- k3: v31 +- k5: # null + k51: v511 +- # null +- # null +- + - + - + - v8111 +- v9 +)"; + std::vector ret_v_token; + std::vector ret_v_cmd; + bool ret = false; + ret = sstd_yaml::_str2token(ret_v_token, s); + //printf("------------------------------------------------------\n"); + //sstd::printn(ret_v_token); + ret = sstd_yaml::_token2cmd(ret_v_cmd, ret_v_token); + //printf("------------------------------------------------------\n"); + //sstd::printn(ret_v_cmd); + //printf("------------------------------------------------------\n"); + + ASSERT_TRUE(ret); + + uint idx=0; + // - + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_alloc); + ASSERT_EQ(ret_v_cmd[idx].hsc, (uint)0); + ASSERT_EQ(ret_v_cmd[idx].type, sstd_yaml::num_list); + ++idx; + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_stack); // stack + ++idx; + // k1: + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_alloc); + ASSERT_EQ(ret_v_cmd[idx].hsc, (uint)2); + ASSERT_EQ(ret_v_cmd[idx].type, sstd_yaml::num_hash); + ASSERT_STREQ(ret_v_cmd[idx].val.c_str(), "k1"); + ++idx; + // v11 + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_assign); + ASSERT_EQ(ret_v_cmd[idx].type, sstd_yaml::num_str); + ASSERT_EQ(ret_v_cmd[idx].format, sstd_yaml::num_block_style_base); + ASSERT_STREQ(ret_v_cmd[idx].val.c_str(), "v11"); + ++idx; + + // - + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_alloc); + ASSERT_EQ(ret_v_cmd[idx].hsc, (uint)0); + ASSERT_EQ(ret_v_cmd[idx].type, sstd_yaml::num_list); + ++idx; + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_stack); // stack + ++idx; + // k2: + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_alloc); + ASSERT_EQ(ret_v_cmd[idx].hsc, (uint)2); + ASSERT_EQ(ret_v_cmd[idx].type, sstd_yaml::num_hash); + ASSERT_STREQ(ret_v_cmd[idx].val.c_str(), "k2"); + ++idx; + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_stack); // stack + ++idx; + + // - + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_alloc); + ASSERT_EQ(ret_v_cmd[idx].hsc, (uint)2); + ASSERT_EQ(ret_v_cmd[idx].type, sstd_yaml::num_list); + ++idx; + // v21 + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_assign); + ASSERT_EQ(ret_v_cmd[idx].type, sstd_yaml::num_str); + ASSERT_EQ(ret_v_cmd[idx].format, sstd_yaml::num_block_style_base); + ASSERT_STREQ(ret_v_cmd[idx].val.c_str(), "v21"); + ++idx; + + // - + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_alloc); + ASSERT_EQ(ret_v_cmd[idx].hsc, (uint)2); + ASSERT_EQ(ret_v_cmd[idx].type, sstd_yaml::num_list); + ++idx; + // v22 + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_assign); + ASSERT_EQ(ret_v_cmd[idx].type, sstd_yaml::num_str); + ASSERT_EQ(ret_v_cmd[idx].format, sstd_yaml::num_block_style_base); + ASSERT_STREQ(ret_v_cmd[idx].val.c_str(), "v22"); + ++idx; + + // - + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_alloc); + ASSERT_EQ(ret_v_cmd[idx].hsc, (uint)2); + ASSERT_EQ(ret_v_cmd[idx].type, sstd_yaml::num_list); + ++idx; + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_stack); // stack + ++idx; + // k23: + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_alloc); + ASSERT_EQ(ret_v_cmd[idx].hsc, (uint)4); + ASSERT_EQ(ret_v_cmd[idx].type, sstd_yaml::num_hash); + ASSERT_STREQ(ret_v_cmd[idx].val.c_str(), "k23"); + ++idx; + + // - + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_alloc); + ASSERT_EQ(ret_v_cmd[idx].hsc, (uint)2); + ASSERT_EQ(ret_v_cmd[idx].type, sstd_yaml::num_list); + ++idx; + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_stack); // stack + ++idx; + // k24: + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_alloc); + ASSERT_EQ(ret_v_cmd[idx].hsc, (uint)4); + ASSERT_EQ(ret_v_cmd[idx].type, sstd_yaml::num_hash); + ASSERT_STREQ(ret_v_cmd[idx].val.c_str(), "k24"); + ++idx; + // v241 + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_assign); + ASSERT_EQ(ret_v_cmd[idx].type, sstd_yaml::num_str); + ASSERT_EQ(ret_v_cmd[idx].format, sstd_yaml::num_block_style_base); + ASSERT_STREQ(ret_v_cmd[idx].val.c_str(), "v241"); + ++idx; + + // - + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_alloc); + ASSERT_EQ(ret_v_cmd[idx].hsc, (uint)0); + ASSERT_EQ(ret_v_cmd[idx].type, sstd_yaml::num_list); + ++idx; + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_stack); // stack + ++idx; + // k3: + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_alloc); + ASSERT_EQ(ret_v_cmd[idx].hsc, (uint)2); + ASSERT_EQ(ret_v_cmd[idx].type, sstd_yaml::num_hash); + ASSERT_STREQ(ret_v_cmd[idx].val.c_str(), "k3"); + ++idx; + // v31 + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_assign); + ASSERT_EQ(ret_v_cmd[idx].type, sstd_yaml::num_str); + ASSERT_EQ(ret_v_cmd[idx].format, sstd_yaml::num_block_style_base); + ASSERT_STREQ(ret_v_cmd[idx].val.c_str(), "v31"); + ++idx; + + // - + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_alloc); + ASSERT_EQ(ret_v_cmd[idx].hsc, (uint)0); + ASSERT_EQ(ret_v_cmd[idx].type, sstd_yaml::num_list); + ++idx; + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_stack); // stack + ++idx; + // k5: #null + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_alloc); + ASSERT_EQ(ret_v_cmd[idx].hsc, (uint)2); + ASSERT_EQ(ret_v_cmd[idx].type, sstd_yaml::num_hash); + ASSERT_STREQ(ret_v_cmd[idx].val.c_str(), "k5"); + ++idx; + + // k51: + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_alloc); + ASSERT_EQ(ret_v_cmd[idx].hsc, (uint)2); + ASSERT_EQ(ret_v_cmd[idx].type, sstd_yaml::num_hash); + ASSERT_STREQ(ret_v_cmd[idx].val.c_str(), "k51"); + ++idx; + // v511 + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_assign); + ASSERT_EQ(ret_v_cmd[idx].type, sstd_yaml::num_str); + ASSERT_EQ(ret_v_cmd[idx].format, sstd_yaml::num_block_style_base); + ASSERT_STREQ(ret_v_cmd[idx].val.c_str(), "v511"); + ++idx; + + // - # null + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_alloc); + ASSERT_EQ(ret_v_cmd[idx].hsc, (uint)0); + ASSERT_EQ(ret_v_cmd[idx].type, sstd_yaml::num_list); + ++idx; + + // - # null + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_alloc); + ASSERT_EQ(ret_v_cmd[idx].hsc, (uint)0); + ASSERT_EQ(ret_v_cmd[idx].type, sstd_yaml::num_list); + ++idx; + + // - + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_alloc); + ASSERT_EQ(ret_v_cmd[idx].hsc, (uint)0); + ASSERT_EQ(ret_v_cmd[idx].type, sstd_yaml::num_list); + ++idx; + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_stack); // stack + ++idx; + // - + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_alloc); + ASSERT_EQ(ret_v_cmd[idx].hsc, (uint)2); + ASSERT_EQ(ret_v_cmd[idx].type, sstd_yaml::num_list); + ++idx; + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_stack); // stack + ++idx; + // - + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_alloc); + ASSERT_EQ(ret_v_cmd[idx].hsc, (uint)4); + ASSERT_EQ(ret_v_cmd[idx].type, sstd_yaml::num_list); + ++idx; + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_stack); // stack + ++idx; + // - + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_alloc); + ASSERT_EQ(ret_v_cmd[idx].hsc, (uint)6); + ASSERT_EQ(ret_v_cmd[idx].type, sstd_yaml::num_list); + ++idx; + // v8111 + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_assign); + ASSERT_EQ(ret_v_cmd[idx].type, sstd_yaml::num_str); + ASSERT_EQ(ret_v_cmd[idx].format, sstd_yaml::num_block_style_base); + ASSERT_STREQ(ret_v_cmd[idx].val.c_str(), "v8111"); + ++idx; + // - + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_alloc); + ASSERT_EQ(ret_v_cmd[idx].hsc, (uint)0); + ASSERT_EQ(ret_v_cmd[idx].type, sstd_yaml::num_list); + ++idx; + // v9 + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_assign); + ASSERT_EQ(ret_v_cmd[idx].type, sstd_yaml::num_str); + ASSERT_EQ(ret_v_cmd[idx].format, sstd_yaml::num_block_style_base); + ASSERT_STREQ(ret_v_cmd[idx].val.c_str(), "v9"); + ++idx; +} + +//--- + +TEST(yaml, _token2cmd_null_values_case01){ + std::string s = R"( +- +- +)"; + std::vector ret_v_token; + std::vector ret_v_cmd; + bool ret = false; + ret = sstd_yaml::_str2token(ret_v_token, s); + ret = sstd_yaml::_token2cmd(ret_v_cmd, ret_v_token); +// sstd::printn(ret_v_cmd); + ASSERT_TRUE(ret); + + uint idx=0; + // - + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_alloc); + ASSERT_EQ(ret_v_cmd[idx].type, sstd_yaml::num_list); + ++idx; + // - + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_alloc); + ASSERT_EQ(ret_v_cmd[idx].type, sstd_yaml::num_list); + ++idx; +} +TEST(yaml, _token2cmd_null_values_case02){ + std::string s = R"( +k1: +k2: +)"; + std::vector ret_v_token; + std::vector ret_v_cmd; + bool ret = false; + ret = sstd_yaml::_str2token(ret_v_token, s); + ret = sstd_yaml::_token2cmd(ret_v_cmd, ret_v_token); +// sstd::printn(ret_v_cmd); + ASSERT_TRUE(ret); + + uint idx=0; + // k1: + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_alloc); + ASSERT_EQ(ret_v_cmd[idx].type, sstd_yaml::num_hash); + ++idx; + // k2: + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_alloc); + ASSERT_EQ(ret_v_cmd[idx].type, sstd_yaml::num_hash); + ++idx; +} +TEST(yaml, _token2cmd_null_values_case03){ + std::string s = R"( +- k1: +- k2: +)"; + std::vector ret_v_token; + std::vector ret_v_cmd; + bool ret = false; + ret = sstd_yaml::_str2token(ret_v_token, s); + ret = sstd_yaml::_token2cmd(ret_v_cmd, ret_v_token); +// sstd::printn(ret_v_cmd); + ASSERT_TRUE(ret); + + uint idx=0; + // - + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_alloc); + ASSERT_EQ(ret_v_cmd[idx].type, sstd_yaml::num_list); + ++idx; + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_stack); // stack + ++idx; + // k1: + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_alloc); + ASSERT_EQ(ret_v_cmd[idx].type, sstd_yaml::num_hash); + ++idx; + // - + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_alloc); + ASSERT_EQ(ret_v_cmd[idx].type, sstd_yaml::num_list); + ++idx; + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_stack); // stack + ++idx; + // k2: + ASSERT_EQ(ret_v_cmd[idx].ope, sstd_yaml::ope_alloc); + ASSERT_EQ(ret_v_cmd[idx].type, sstd_yaml::num_hash); + ++idx; +} +//*/ +//----------------------------------------------------------------------------------------------------------------------------------------------- +// comments +//* +TEST(yaml, comments_str){ std::string s=R"( a # comment )"; @@ -15,41 +962,31 @@ a # comment sstd::terp::var ans; ans = "a"; + //sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } -TEST(yaml, var_str_2_lines_err){ +TEST(yaml, comments_str_quotes){ std::string s=R"( -a # comment -b +"a # not-comment" # comment )"; - testing::internal::CaptureStdout(); sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE - std::string ret = testing::internal::GetCapturedStdout().c_str(); - ASSERT_TRUE(sstd::strIn("OverWritting the existing data. (String data type can only take one data.)", ret.c_str())); //sstd::printn(yml); //--- sstd::terp::var ans; - ans = "a"; + ans = "a # not-comment"; //--- ASSERT_TRUE(yml==ans); } - -//----------------------------------------------------------------------------------------------------------------------------------------------- -// list - -TEST(yaml, list_depth1){ +TEST(yaml, comments_list){ std::string s=R"( - a # comment -- b - -- c )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -57,23 +994,17 @@ TEST(yaml, list_depth1){ //--- sstd::terp::var ans; - ans = sstd::terp::list(3); + ans = sstd::terp::list(1); ans[0] = "a"; - ans[1] = "b"; - ans[2] = "c"; + //sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } -TEST(yaml, list_depth2){ +TEST(yaml, comments_list_quotes){ std::string s=R"( -- a # comment -- b -- - - c - - d -- e +- "a # not-comment" # comment )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -81,52 +1012,34 @@ TEST(yaml, list_depth2){ //--- sstd::terp::var ans; - ans = sstd::terp::list(4); - ans[0] = "a"; - ans[1] = "b"; - ans[2] = sstd::terp::list(2); - ans[2][0] = "c"; - ans[2][1] = "d"; - ans[3] = "e"; + ans = sstd::terp::list(1); + ans[0] = "a # not-comment"; //--- ASSERT_TRUE(yml==ans); } - -//----------------------------------------------------------------------------------------------------------------------------------------------- -// hash - -TEST(yaml, hash_depth1){ +TEST(yaml, comments_hash){ std::string s=R"( -k1: v1 # comment -k2: v2 - -k3: v3 +k: v # comment )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE - //sstd::printn(yml); +// sstd::printn(yml); //--- sstd::terp::var ans; ans = sstd::terp::hash(); - ans["k1"] = "v1"; - ans["k2"] = "v2"; - ans["k3"] = "v3"; + ans["k"] = "v"; +// sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } -TEST(yaml, hash_depth2){ +TEST(yaml, comments_hash_quotes){ std::string s=R"( -k1: v1 # comment -k2: v2 -k3: - k31: v31 - k32: v32 -k4: v4 +"k # not-comment": "v # not-comment" # comment )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -135,24 +1048,20 @@ k4: v4 sstd::terp::var ans; ans = sstd::terp::hash(); - ans["k1"] = "v1"; - ans["k2"] = "v2"; - ans["k3"] = sstd::terp::hash(); - ans["k3"]["k31"] = "v31"; - ans["k3"]["k32"] = "v32"; - ans["k4"] = "v4"; + ans["k # not-comment"] = "v # not-comment"; + //sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } - +//*/ //----------------------------------------------------------------------------------------------------------------------------------------------- -// list and hash - -TEST(yaml, list_and_hash__NUM_LIST_AND_HASH){ +// var +//* +TEST(yaml, var_str_1_line){ std::string s=R"( -- k1: v1 +a # comment )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -160,147 +1069,213 @@ TEST(yaml, list_and_hash__NUM_LIST_AND_HASH){ //--- sstd::terp::var ans; - ans = sstd::terp::list(1); - ans[0] = sstd::terp::hash(); - ans[0]["k1"] = "v1"; - //sstd::printn(ans); + ans = "a"; //--- ASSERT_TRUE(yml==ans); } - -//----------------------------------------------------------------------------------------------------------------------------------------------- -// complex test cases - -TEST(yaml, list_hash_case01_01){ // depth2 +TEST(yaml, var_str_2_lines_err){ + // I feeel it is difficult to read which method is appropriate for the handling of multi -line comments from the specifications. + // Memo: checking again: "Example 6.11 Multi-Line Comments" at the specification (https://yaml.org/spec/1.2.2/#rule-ns-hex-digit) + std::string s=R"( -- k1: v1 +a # comment +b )"; - sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE - //sstd::printn(yml); - + sstd::terp::var yml; + bool ret = sstd::yaml_load(yml, s); // TEST THIS LINE + //testing::internal::CaptureStdout(); + //sstd::terp::var yml; ASSERT_FALSE(sstd::yaml_load(yml, s)); // TEST THIS LINE + //std::string ret = testing::internal::GetCapturedStdout().c_str(); + //sstd::printn(ret); + //ASSERT_TRUE(sstd::strIn("OverWritting the existing data.", ret.c_str())); +// sstd::printn(yml); + //--- sstd::terp::var ans; - ans = sstd::terp::list(1); - ans[0] = sstd::terp::hash(); - ans[0]["k1"] = "v1"; + ans = "a b"; //--- + ASSERT_TRUE(ret); ASSERT_TRUE(yml==ans); } -TEST(yaml, list_hash_case01_02){ // depth2 +//*/ +//----------------------------------------------------------------------------------------------------------------------------------------------- +// list +//* +TEST(yaml, list_depth1){ std::string s=R"( -- k1: v1 -- k2: v2 +- a # comment +- b + +- c )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE - //sstd::printn(yml); - +// sstd::printn(yml); + //--- sstd::terp::var ans; - ans = sstd::terp::list(2); - ans[0] = sstd::terp::hash(); - ans[0]["k1"] = "v1"; - ans[1] = sstd::terp::hash(); - ans[1]["k2"] = "v2"; + ans = sstd::terp::list(3); + ans[0] = "a"; + ans[1] = "b"; + ans[2] = "c"; +// sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } -TEST(yaml, list_hash_case01_03){ // depth2 +TEST(yaml, list_depth2){ std::string s=R"( -- k1: v1 -- k2: v2 -- k3: v3 +- a # comment +- b +- + - c + - d +- e )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE - //sstd::printn(yml); - +// sstd::printn(yml); + //--- sstd::terp::var ans; - ans = sstd::terp::list(3); - ans[0] = sstd::terp::hash(); - ans[0]["k1"] = "v1"; - ans[1] = sstd::terp::hash(); - ans[1]["k2"] = "v2"; - ans[2] = sstd::terp::hash(); - ans[2]["k3"] = "v3"; + ans = sstd::terp::list(4); + ans[0] = "a"; + ans[1] = "b"; + ans[2] = sstd::terp::list(2); + ans[2][0] = "c"; + ans[2][1] = "d"; + ans[3] = "e"; +// sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } -TEST(yaml, list_hash_case01_04){ // depth2 + +//--- +// Corner case(s) + +TEST(yaml, list_colon){ std::string s=R"( -- - - k1: v1 - - k2: v2 -- k3: v3 +- a:a )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::list(1); + ans[0] = "a:a"; //--- + ASSERT_TRUE(yml==ans); +} +TEST(yaml, list_flow_style_brackets){ + std::string s=R"( +- a[] # OK +- a{} # OK +#- []a # NG +#- {}a # NG +#- ][a # NG +#- }{a # NG +)"; + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE + //sstd::printn(yml); + + //--- + sstd::terp::var ans; ans = sstd::terp::list(2); - ans[0] = sstd::terp::list(2); - ans[0][0] = sstd::terp::hash(); - ans[0][0]["k1"] = "v1"; - ans[0][1] = sstd::terp::hash(); - ans[0][1]["k2"] = "v2"; - ans[1] = sstd::terp::hash(); - ans[1]["k3"] = "v3"; + ans[0] = "a[]"; + ans[1] = "a{}"; //--- ASSERT_TRUE(yml==ans); } -TEST(yaml, list_hash_case02){ // depth2 +TEST(yaml, list_null){ std::string s=R"( -- a # comment -- b +- +- +- +)"; + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE +// sstd::printn(yml); -- k1: v1 - k2: v2 -- c + //--- + + sstd::terp::var ans; + ans = sstd::terp::list(3); +// sstd::printn(ans); + + //--- + + ASSERT_TRUE(yml==ans); +} +TEST(yaml, list_str_listStr_listStrEnd){ // depth1 + std::string s=R"( +- a - b - c - )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE - //sstd::printn(yml); +// sstd::printn(yml); +// sstd::printn(yml.size()); //--- sstd::terp::var ans; - ans = sstd::terp::list(4); - ans[0] = "a"; - ans[1] = "b"; - ans[2] = sstd::terp::hash(); - ans[2]["k1"] = "v1"; - ans[2]["k2"] = "v2"; - ans[3] = "c"; + ans = sstd::terp::list(1); + ans[0] = "a - b - c -"; //--- ASSERT_TRUE(yml==ans); } +//*/ +//----------------------------------------------------------------------------------------------------------------------------------------------- +// hash +//* +TEST(yaml, hash_depth1){ + std::string s=R"( +k1: v1 # comment +k2: v2 -TEST(yaml, hash_list){ // depth2 +k3: v3 +)"; + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE + //sstd::printn(yml); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::hash(); + ans["k1"] = "v1"; + ans["k2"] = "v2"; + ans["k3"] = "v3"; + //sstd::printn(ans); + + //--- + + ASSERT_TRUE(yml==ans); +} +TEST(yaml, hash_depth2){ std::string s=R"( k1: v1 # comment k2: v2 k3: - - v31 - - v32 + k31: v31 + k32: v32 k4: v4 )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE - //sstd::printn(yml); +// sstd::printn(yml); //--- @@ -308,10 +1283,11 @@ k4: v4 ans = sstd::terp::hash(); ans["k1"] = "v1"; ans["k2"] = "v2"; - ans["k3"] = sstd::terp::list(2); - ans["k3"][0] = "v31"; - ans["k3"][1] = "v32"; + ans["k3"] = sstd::terp::hash(); + ans["k3"]["k31"] = "v31"; + ans["k3"]["k32"] = "v32"; ans["k4"] = "v4"; +// sstd::printn(ans); //--- @@ -319,95 +1295,1298 @@ k4: v4 } //--- +// Corner case(s) -TEST(yaml, list_hash_list){ // depth3 +TEST(yaml, hash_null_case01){ std::string s=R"( -- a # comment -- b +k1: +)"; + sstd::terp::var yml; bool ret_tf = sstd::yaml_load(yml, s); // TEST THIS LINE +// sstd::printn(yml); + ASSERT_TRUE(ret_tf); -- k1: v1 - k2: - - v21 - - v22 - - v23 - k3: v3 -- c + //--- + + sstd::terp::var ans; + ans = sstd::terp::hash(); + ans["k1"]; +// sstd::printn(ans); + + //--- + + ASSERT_TRUE(yml==ans); +} +TEST(yaml, hash_null_case02){ + std::string s=R"( +k1: +k2: )"; - sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE + sstd::terp::var yml; bool ret_tf = sstd::yaml_load(yml, s); // TEST THIS LINE +// sstd::printn(yml); + ASSERT_TRUE(ret_tf); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::hash(); + ans["k1"]; + ans["k2"]; +// sstd::printn(ans); + + //--- + + ASSERT_TRUE(yml==ans); +} +//* +TEST(yaml, hash_with_colon_01){ + std::string s=R"( +k:1: v:1 +)"; + sstd::terp::var yml; bool ret_tf = sstd::yaml_load(yml, s); // TEST THIS LINE //sstd::printn(yml); + ASSERT_TRUE(ret_tf); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::hash(); + ans["k:1"] = "v:1"; + + //--- + ASSERT_TRUE(yml==ans); +} +TEST(yaml, hash_with_colon_02){ + std::string s=R"( +k:1:: v:1 +)"; + sstd::terp::var yml; bool ret_tf = sstd::yaml_load(yml, s); // TEST THIS LINE + //sstd::printn(yml); + ASSERT_TRUE(ret_tf); + //--- sstd::terp::var ans; - ans = sstd::terp::list(4); - ans[0] = "a"; - ans[1] = "b"; - ans[2] = sstd::terp::hash(); - ans[2]["k1"] = "v1"; - ans[2]["k2"] = sstd::terp::list(3); - ans[2]["k2"][0] = "v21"; - ans[2]["k2"][1] = "v22"; - ans[2]["k2"][2] = "v23"; - ans[2]["k3"] = "v3"; - ans[3] = "c"; - //sstd::printn(ans); + ans = sstd::terp::hash(); + ans["k:1:"] = "v:1"; //--- ASSERT_TRUE(yml==ans); } +TEST(yaml, hash_with_colon_03){ + std::string s=R"( +k:1::: v:1 +)"; + sstd::terp::var yml; bool ret_tf = sstd::yaml_load(yml, s); // TEST THIS LINE + //sstd::printn(yml); + ASSERT_TRUE(ret_tf); -TEST(yaml, hash_list_hash){ // depth3 + //--- + + sstd::terp::var ans; + ans = sstd::terp::hash(); + ans["k:1::"] = "v:1"; + + //--- + + ASSERT_TRUE(yml==ans); +} +TEST(yaml, hash_with_colon_04){ std::string s=R"( -k1: v1 # comment -k2: v2 -k3: - - v31 - - k32: v321 - - v33 -k4: v4 +k:1: a":":a )"; - sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE + sstd::terp::var yml; bool ret_tf = sstd::yaml_load(yml, s); // TEST THIS LINE //sstd::printn(yml); + ASSERT_TRUE(ret_tf); //--- sstd::terp::var ans; ans = sstd::terp::hash(); - ans["k1"] = "v1"; - ans["k2"] = "v2"; - ans["k3"] = sstd::terp::list(3); - ans["k3"][0] = "v31"; - ans["k3"][1] = sstd::terp::hash(); - ans["k3"][1]["k32"] = "v321"; - ans["k3"][2] = "v33"; - ans["k4"] = "v4"; - //sstd::printn(ans); + ans["k:1"] = "a\":\":a"; + + //--- + + ASSERT_TRUE(yml==ans); +} +TEST(yaml, hash_flow_style_brackets){ + std::string s=R"( +k[]{}: v[]{} # OK +#[]k: []v # NG +#][k: ][v # NG +#{}k: {}v # NG +#}{k: }{v # NG +)"; + sstd::terp::var yml; bool ret_tf = sstd::yaml_load(yml, s); // TEST THIS LINE + //sstd::printn(yml); + ASSERT_TRUE(ret_tf); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::hash(); + ans["k[]{}"] = "v[]{}"; + + //--- + + ASSERT_TRUE(yml==ans); +} + +//--- + +TEST(yaml, hash_duplicated_err){ // TODO: ここの仕様を直す + std::string s=R"( +k1: val1 +k1: valX +)"; + testing::internal::CaptureStdout(); + sstd::terp::var yml; bool ret_tf = sstd::yaml_load(yml, s); // TEST THIS LINE + ASSERT_TRUE(ret_tf==false); + std::string ret = testing::internal::GetCapturedStdout().c_str(); + ASSERT_TRUE(sstd::strIn("Detecting the duplicated hash key.", ret.c_str())); // Do NOT check +// sstd::printn(yml); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::hash(); + ans["k1"] = "val1"; + //ans["k1"] = "valX"; +// sstd::printn(ans); + + //--- + + ASSERT_TRUE(yml==ans); +} + +//----------------------------------------------------------------------------------------------------------------------------------------------- +// list and hash + +TEST(yaml, list_and_hash__NUM_LIST_AND_HASH){ + std::string s=R"( +- k1: v1 +)"; + sstd::terp::var yml; bool ret_tf = sstd::yaml_load(yml, s); // TEST THIS LINE +// sstd::printn(yml); + ASSERT_TRUE(ret_tf); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::list(1); + ans[0] = sstd::terp::hash(); + ans[0]["k1"] = "v1"; +// sstd::printn(ans); + + //--- + + ASSERT_TRUE(yml==ans); +} +TEST(yaml, list_and_hash__conbined){ + std::string s=R"( +- k1: + - v11 + - v12 +- v2 +)"; + sstd::terp::var yml; bool ret_tf = sstd::yaml_load(yml, s); // TEST THIS LINE +// sstd::printn(yml); + ASSERT_TRUE(ret_tf); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::list(2); + ans[0] = sstd::terp::hash(); + ans[0]["k1"] = sstd::terp::list(2); + ans[0]["k1"][0] = "v11"; + ans[0]["k1"][1] = "v12"; + ans[1] = "v2"; +// sstd::printn(ans); + + //--- + + ASSERT_TRUE(yml==ans); +} + +//--- +// Corner case(s) + +TEST(yaml, list_and_hash__colon){ + std::string s=R"( +- k:1::: a":":a +)"; + sstd::terp::var yml; bool ret_tf = sstd::yaml_load(yml, s); // TEST THIS LINE + //sstd::printn(yml); + ASSERT_TRUE(ret_tf); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::list(1); + ans[0] = sstd::terp::hash(); + ans[0]["k:1::"] = "a\":\":a"; + //sstd::printn(ans); + + //--- + + ASSERT_TRUE(yml==ans); +} +TEST(yaml, list_and_hash_flow_style_brackets){ + std::string s=R"( +- a[]: a[] # OK +- a{}: a{} # OK +#- []a: []a # NG (Invalid) +#- ][a: ][a # NG (Invalid) +#- {}a: {}a # NG (Invalid) +#- }{a: }{a # NG (Invalid) +)"; + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE + //sstd::printn(yml); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::list(2); + ans[0] = sstd::terp::hash(); + ans[0]["a[]"] = "a[]"; + ans[1] = sstd::terp::hash(); + ans[1]["a{}"] = "a{}"; + + //--- + + ASSERT_TRUE(yml==ans); +} +//*/ +//----------------------------------------------------------------------------------------------------------------------------------------------- +// complex test cases +//* +TEST(yaml, list_hash_case01_01){ // depth2 + std::string s=R"( +- k1: v1 +)"; + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE + //sstd::printn(yml); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::list(1); + ans[0] = sstd::terp::hash(); + ans[0]["k1"] = "v1"; + + //--- + + ASSERT_TRUE(yml==ans); +} +TEST(yaml, list_hash_case01_02){ // depth2 + std::string s=R"( +- k1: v1 +- k2: v2 +)"; + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE +// sstd::printn(yml); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::list(2); + ans[0] = sstd::terp::hash(); + ans[0]["k1"] = "v1"; + ans[1] = sstd::terp::hash(); + ans[1]["k2"] = "v2"; +// sstd::printn(ans); + + //--- + + ASSERT_TRUE(yml==ans); +} +TEST(yaml, list_hash_case01_03){ // depth2 + std::string s=R"( +- k1: v1 +- k2: v2 +- k3: v3 +)"; + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE + //sstd::printn(yml); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::list(3); + ans[0] = sstd::terp::hash(); + ans[0]["k1"] = "v1"; + ans[1] = sstd::terp::hash(); + ans[1]["k2"] = "v2"; + ans[2] = sstd::terp::hash(); + ans[2]["k3"] = "v3"; + + //--- + + ASSERT_TRUE(yml==ans); +} +TEST(yaml, list_hash_case01_04){ // depth2 + std::string s=R"( +- + - k1: v1 + - k2: v2 +- k3: v3 +)"; + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE + //sstd::printn(yml); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::list(2); + ans[0] = sstd::terp::list(2); + ans[0][0] = sstd::terp::hash(); + ans[0][0]["k1"] = "v1"; + ans[0][1] = sstd::terp::hash(); + ans[0][1]["k2"] = "v2"; + ans[1] = sstd::terp::hash(); + ans[1]["k3"] = "v3"; + + //--- + + ASSERT_TRUE(yml==ans); +} +TEST(yaml, list_hash_case02){ // depth2 + std::string s=R"( +- a # comment +- b + +- k1: v1 + k2: v2 + k3: v3 +- k3: + k4: v4 +- c +)"; + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE +// sstd::printn(yml); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::list(5); + ans[0] = "a"; + ans[1] = "b"; + ans[2] = sstd::terp::hash(); + ans[2]["k1"] = "v1"; + ans[2]["k2"] = "v2"; + ans[2]["k3"] = "v3"; + ans[3] = sstd::terp::hash(); + ans[3]["k3"]; + ans[3]["k4"] = "v4"; + ans[4] = "c"; +// sstd::printn(ans); + + //--- + + ASSERT_TRUE(yml==ans); +} + +TEST(yaml, hash_list){ // depth2 + std::string s=R"( +k1: v1 # comment +k2: v2 +k3: + - v31 + - v32 +k4: v4 +)"; + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE +// sstd::printn(yml); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::hash(); + ans["k1"] = "v1"; + ans["k2"] = "v2"; + ans["k3"] = sstd::terp::list(2); + ans["k3"][0] = "v31"; + ans["k3"][1] = "v32"; + ans["k4"] = "v4"; +// sstd::printn(ans); + + //--- + + ASSERT_TRUE(yml==ans); +} + +//--- + +TEST(yaml, list_hash_list_case01){ // depth3 + std::string s=R"( +- a # comment +- b + +- k1: v1 + k2: + - v21 + - v22 + - v23 + k3: v3 +- c +)"; + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE +// sstd::printn(yml); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::list(4); + ans[0] = "a"; + ans[1] = "b"; + ans[2] = sstd::terp::hash(); + ans[2]["k1"] = "v1"; + ans[2]["k2"] = sstd::terp::list(3); + ans[2]["k2"][0] = "v21"; + ans[2]["k2"][1] = "v22"; + ans[2]["k2"][2] = "v23"; + ans[2]["k3"] = "v3"; + ans[3] = "c"; +// Sstd::printn(ans); + + //--- + + ASSERT_TRUE(yml==ans); +} +TEST(yaml, list_hash_list_case02){ // depth3 + std::string s=R"( + # hsc_lx, hsc_hx +- a # 0, 2 +- b # 0, 2 + +- k1: # 0, 2 + - v11 # 4, 4 + - v12 # 4, 4 + - v13 # 4, 4 + k2: # 2, 2 + - v21 # 4, 4 + - v22 # 4, 4 + - v23 # 4, 4 + k3: v3 # 2, 2 +- c # 0, 2 +)"; + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE +// sstd::printn(yml); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::list(4); + ans[0] = "a"; + ans[1] = "b"; + ans[2] = sstd::terp::hash(); + ans[2]["k1"] = sstd::terp::list(3); + ans[2]["k1"][0] = "v11"; + ans[2]["k1"][1] = "v12"; + ans[2]["k1"][2] = "v13"; + ans[2]["k2"] = sstd::terp::list(3); + ans[2]["k2"][0] = "v21"; + ans[2]["k2"][1] = "v22"; + ans[2]["k2"][2] = "v23"; + ans[2]["k3"] = "v3"; + ans[3] = "c"; +// sstd::printn(ans); + + //--- + + ASSERT_TRUE(yml==ans); +} + +TEST(yaml, hash_list_hash){ // depth3 + std::string s=R"( +k1: v1 # comment +k2: v2 +k3: + - v31 + - k32: v321 + - v33 +k4: v4 +)"; + sstd::terp::var yml; bool ret_tf = sstd::yaml_load(yml, s); // TEST THIS LINE +// sstd::printn(yml); + ASSERT_TRUE(ret_tf); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::hash(); + ans["k1"] = "v1"; + ans["k2"] = "v2"; + ans["k3"] = sstd::terp::list(3); + ans["k3"][0] = "v31"; + ans["k3"][1] = sstd::terp::hash(); + ans["k3"][1]["k32"] = "v321"; + ans["k3"][2] = "v33"; + ans["k4"] = "v4"; +// sstd::printn(ans); + + //--- + + ASSERT_TRUE(yml==ans); +} + +//--- + +TEST(yaml, list_hash_list_hash){ // depth4 +} + +//--- + +TEST(yaml, hash_list_hash_list){ // depth4 + std::string s=R"( +k1: v1 # comment +k2: v2 +k3: + - v31 + - k32: + - v321 + - v322 + - v323 + - v33 +k4: v4 +)"; + sstd::terp::var yml; bool ret_tf = sstd::yaml_load(yml, s); // TEST THIS LINE +// sstd::printn(yml); + ASSERT_TRUE(ret_tf); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::hash(); + ans["k1"] = "v1"; + ans["k2"] = "v2"; + ans["k3"] = sstd::terp::list(3); + ans["k3"][0] = "v31"; + ans["k3"][1] = sstd::terp::hash(); + ans["k3"][1]["k32"] = sstd::terp::list(3); + ans["k3"][1]["k32"][0] = "v321"; + ans["k3"][1]["k32"][1] = "v322"; + ans["k3"][1]["k32"][2] = "v323"; + ans["k3"][2] = "v33"; + ans["k4"] = "v4"; +// sstd::printn(ans); + + //--- + + ASSERT_TRUE(yml==ans); +} +//*/ +//----------------------------------------------------------------------------------------------------------------------------------------------- +// ignore ! option + + +//----------------------------------------------------------------------------------------------------------------------------------------------- +// TypeConversion + +// Note. TypeConversion segment is implemented and tested on terp.cpp/hpp. + +// to +// to +// to +// to +// to +// to +// to +// to +// to +// to +// to +// to +// to +// to +// to +// to + +//----------------------------------------------------------------------------------------------------------------------------------------------- +// Multi line string for list +//* +TEST(yaml, multi_line_str_by_list_vertical_line){ // - | + std::string s=R"( +- a # comment +- | + b1 + b2 + b3 + + +- c +)"; + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE +// sstd::printn(yml); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::list(3); + ans[0] = "a"; + ans[1] = "b1\nb2\nb3\n"; + ans[2] = "c"; +// sstd::printn(ans); + + //--- + + ASSERT_TRUE(yml==ans); +} + +TEST(yaml, multi_line_str_by_list_vertical_line_minus){ // - |- + std::string s=R"( +- a # comment +- |- + b1 + b2 + b3 + + +- c +)"; + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE + //sstd::printn(yml); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::list(3); + ans[0] = "a"; + ans[1] = "b1\nb2\nb3"; + ans[2] = "c"; + + //--- + + ASSERT_TRUE(yml==ans); +} + +TEST(yaml, multi_line_str_by_list_vertical_line_plus){ // - |+ + std::string s=R"( +- a # comment +- |+ + b1 + b2 + b3 + + +- c +)"; + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE + //sstd::printn(yml); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::list(3); + ans[0] = "a"; + ans[1] = "b1\nb2\nb3\n\n\n"; + ans[2] = "c"; + + //--- + + ASSERT_TRUE(yml==ans); +} + +// TEST(yaml, multi_line_str_by_list_vertical_line_num_0){ // - |0 (Can't set 0. Because of the indent under list struct is equal or larger than 1) +// } + +TEST(yaml, multi_line_str_by_list_vertical_line_num_1){ // - |1 + std::string s=R"( +- a # comment +- |1 + b1 + b2 + b3 + + +- c +)"; + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE + //sstd::printn(yml); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::list(3); + ans[0] = "a"; + ans[1] = " b1\n b2\n b3\n"; + ans[2] = "c"; + + //--- + + ASSERT_TRUE(yml==ans); +} + +TEST(yaml, multi_line_str_by_list_vertical_line_num_1_case02){ // - |1 + std::string s=R"( +- a # comment +- |1 + b1 + b2 + b3 + + +- c +)"; + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE + //sstd::printn(yml); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::list(3); + ans[0] = "a"; + ans[1] = "b1\n b2\nb3\n"; + ans[2] = "c"; + + //--- + + ASSERT_TRUE(yml==ans); +} + +TEST(yaml, multi_line_str_by_list_vertical_line_num_2){ // - |2 + std::string s=R"( +- a # comment +- |2 + b1 + b2 + b3 + + +- c +)"; + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE + //sstd::printn(yml); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::list(3); + ans[0] = "a"; + ans[1] = "b1\nb2\nb3\n"; + ans[2] = "c"; + + //--- + + ASSERT_TRUE(yml==ans); +} + +// TEST(yaml, multi_line_str_by_list_vertical_line_minus_num_0){ // - |-0 (Can't set 0. Because of the indent under list struct is equal or larger than 1) +// } + +TEST(yaml, multi_line_str_by_list_vertical_line_minus_num_1){ + std::string s=R"( +- a # comment +- |-1 + b1 + b2 + b3 + + +- c +)"; + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE + //sstd::printn(yml); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::list(3); + ans[0] = "a"; + ans[1] = " b1\n b2\n b3"; + ans[2] = "c"; + + //--- + + ASSERT_TRUE(yml==ans); +} + +// TEST(yaml, multi_line_str_by_list_vertical_line_plus_num_0){ // - |+0 (Can't set 0. Because of the indent under list struct is equal or larger than 1) +// } + +TEST(yaml, multi_line_str_by_list_vertical_line_plus_num_1){ + std::string s=R"( +- a # comment +- |+1 + b1 + b2 + b3 + + +- c +)"; + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE + //sstd::printn(yml); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::list(3); + ans[0] = "a"; + ans[1] = " b1\n b2\n b3\n\n\n"; + ans[2] = "c"; + + //--- + + ASSERT_TRUE(yml==ans); +} + +TEST(yaml, multi_line_str_by_list_vertical_line_with_different_head_spaces__vertical){ + std::string s=R"( +- | + a + b + c + d + e +)"; + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE +// sstd::printn(yml); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::list(1); + ans[0] = "a\nb\n c\n d\ne\n"; + //sstd::printn(ans); + + //--- + + ASSERT_TRUE(yml==ans); +} +TEST(yaml, multi_line_str_by_list_vertical_line_with_different_head_spaces__vertical_1){ + std::string s=R"( +- |1 + a + b + c + d + e +)"; + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE + //sstd::printn(yml); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::list(1); + ans[0] = " a\n b\n c\n d\n e\n"; + //sstd::printn(ans); + + //--- + + ASSERT_TRUE(yml==ans); +} +TEST(yaml, multi_line_str_by_list_vertical_line_with_different_head_spaces__vertical_minus){ + std::string s=R"( +- |- + a + b + c + d + e +)"; + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE + //sstd::printn(yml); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::list(1); + ans[0] = "a\nb\n c\n d\ne"; + //sstd::printn(ans); + + //--- + + ASSERT_TRUE(yml==ans); +} + +//--- + +TEST(yaml, multi_line_str_by_list_greater){ // - > + std::string s=R"( +- a # comment +- > + b1 + b2 + b3 + + +- c +)"; + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE + //sstd::printn(yml); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::list(3); + ans[0] = "a"; + ans[1] = "b1 b2 b3\n"; + ans[2] = "c"; + + //--- + + ASSERT_TRUE(yml==ans); +} + +TEST(yaml, multi_line_str_by_list_greater_minus){ // - >- + std::string s=R"( +- a # comment +- >- + b1 + b2 + b3 + + +- c +)"; + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE + //sstd::printn(yml); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::list(3); + ans[0] = "a"; + ans[1] = "b1 b2 b3"; + ans[2] = "c"; + + //--- + + ASSERT_TRUE(yml==ans); +} + +TEST(yaml, multi_line_str_by_list_greater_plus){ // - >+ + std::string s=R"( +- a # comment +- >+ + b1 + b2 + b3 + + +- c +)"; + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE + //sstd::printn(yml); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::list(3); + ans[0] = "a"; + ans[1] = "b1 b2 b3\n\n\n"; + ans[2] = "c"; + + //--- + + ASSERT_TRUE(yml==ans); +} + +// TEST(yaml, multi_line_str_by_list_greater_num_0){ // - >0 (Can't set 0. Because of the indent under list struct is equal or larger than 1) +// } + +TEST(yaml, multi_line_str_by_list_greater_num_1){ // - >1 + std::string s=R"( +- a # comment +- >1 + b1 + b2 + b3 + + +- c +)"; + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE + //sstd::printn(yml); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::list(3); + ans[0] = "a"; + ans[1] = " b1\n b2\n b3\n"; + ans[2] = "c"; + + //--- + + ASSERT_TRUE(yml==ans); +} +TEST(yaml, multi_line_str_by_list_greater_num_1_case02){ // - >1 + std::string s=R"( +- a # comment +- + - >1 + b1 + b2 + b3 + + +- c +)"; + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE +// sstd::printn(yml); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::list(3); + ans[0] = "a"; + ans[1] = sstd::terp::list(1); + ans[1][0] = " b1\n b2\n b3\n"; + ans[2] = "c"; + + //--- + + ASSERT_TRUE(yml==ans); +} +TEST(yaml, multi_line_str_by_list_greater_num_2){ // - >2 + std::string s=R"( +- a # comment +- >2 + b1 + b2 + b3 + + +- c +)"; + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE + //sstd::printn(yml); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::list(3); + ans[0] = "a"; + ans[1] = "b1 b2 b3\n"; + ans[2] = "c"; + + //--- + + ASSERT_TRUE(yml==ans); +} + +TEST(yaml, multi_line_str_by_list_greater_num_4){ // - >4 + std::string s=R"( +- a # comment +- + - >4 + b1 + b2 + b3 + + +- c +)"; + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE + //sstd::printn(yml); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::list(3); + ans[0] = "a"; + ans[1] = sstd::terp::list(1); + ans[1][0] = "b1 b2 b3\n"; + ans[2] = "c"; + + //--- + + ASSERT_TRUE(yml==ans); +} + +TEST(yaml, multi_line_str_by_list_greater_minus_num_1){ // - >-1 + std::string s=R"( +- a # comment +- >-1 + b1 + b2 + b3 + + +- c +)"; + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE +// sstd::printn(yml); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::list(3); + ans[0] = "a"; + ans[1] = " b1\n b2\n b3"; + ans[2] = "c"; +// sstd::printn(ans); + + //--- + + ASSERT_TRUE(yml==ans); +} + +// TEST(yaml, multi_line_str_by_list_greater_minus_num_2){ // - >-2 +// } + +// TEST(yaml, multi_line_str_by_list_greater_plus_num_1){ // - >-1 +// } + +// TEST(yaml, multi_line_str_by_list_greater_plus_num_2){ // - >-2 +// } +//*/ +//----------------------------------------------------------------------------------------------------------------------------------------------- +// Multi line string for hash +//* +TEST(yaml, multi_line_str_by_hash_vertical_line){ // : | + std::string s=R"( +k1: a # comment +k2: | + b1 + b2 + b3 + + +k3: c +)"; + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE + //sstd::printn(yml); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::hash(); + ans["k1"] = "a"; + ans["k2"] = "b1\nb2\nb3\n"; + ans["k3"] = "c"; + + //--- + + ASSERT_TRUE(yml==ans); +} + +TEST(yaml, multi_line_str_by_hash_vertical_line_minus){ // : |- + std::string s=R"( +k1: a # comment +k2: |- + b1 + b2 + b3 + + +k3: c +)"; + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE + //sstd::printn(yml); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::hash(); + ans["k1"] = "a"; + ans["k2"] = "b1\nb2\nb3"; + ans["k3"] = "c"; + + //--- + + ASSERT_TRUE(yml==ans); +} + +TEST(yaml, multi_line_str_by_hash_vertical_line_plus){ // : |+ + std::string s=R"( +k1: a # comment +k2: |+ + b1 + b2 + b3 + + +k3: c +)"; + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE + //sstd::printn(yml); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::hash(); + ans["k1"] = "a"; + ans["k2"] = "b1\nb2\nb3\n\n\n"; + ans["k3"] = "c"; + + //--- + + ASSERT_TRUE(yml==ans); +} + +// TEST(yaml, multi_line_str_by_hash_vertical_line_num_0){ // : |0 (Can't set 0. Because of the indent under hash struct is equal or larger than 1) +// } + +TEST(yaml, multi_line_str_by_hash_vertical_line_num_1){ // : |1 + std::string s=R"( +k1: a # comment +k2: |1 + b1 + b2 + b3 + + +k3: c +)"; + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE + //sstd::printn(yml); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::hash(); + ans["k1"] = "a"; + ans["k2"] = " b1\n b2\n b3\n"; + ans["k3"] = "c"; + + //--- + + ASSERT_TRUE(yml==ans); +} + +TEST(yaml, multi_line_str_by_hash_vertical_line_num_2){ // : |2 + std::string s=R"( +k1: a # comment +k2: |2 + b1 + b2 + b3 + + +k3: c +)"; + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE + //sstd::printn(yml); + + //--- + + sstd::terp::var ans; + ans = sstd::terp::hash(); + ans["k1"] = "a"; + ans["k2"] = "b1\nb2\nb3\n"; + ans["k3"] = "c"; //--- ASSERT_TRUE(yml==ans); } -//--- - -TEST(yaml, list_hash_list_hash){ // depth4 -} +TEST(yaml, multi_line_str_by_hash_vertical_line_minus_num_1){ // : |-1 + std::string s=R"( +k1: a # comment +k2: |-1 + b1 + b2 + b3 -//--- -TEST(yaml, hash_list_hash_list){ // depth4 - std::string s=R"( -k1: v1 # comment -k2: v2 -k3: - - v31 - - k32: - - v321 - - v322 - - v323 - - v33 -k4: v4 +k3: c )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -416,63 +2595,36 @@ k4: v4 sstd::terp::var ans; ans = sstd::terp::hash(); - ans["k1"] = "v1"; - ans["k2"] = "v2"; - ans["k3"] = sstd::terp::list(3); - ans["k3"][0] = "v31"; - ans["k3"][1] = sstd::terp::hash(); - ans["k3"][1]["k32"] = sstd::terp::list(3); - ans["k3"][1]["k32"][0] = "v321"; - ans["k3"][1]["k32"][1] = "v322"; - ans["k3"][1]["k32"][2] = "v323"; - ans["k3"][2] = "v33"; - ans["k4"] = "v4"; - //sstd::printn(ans); + ans["k1"] = "a"; + ans["k2"] = " b1\n b2\n b3"; + ans["k3"] = "c"; //--- ASSERT_TRUE(yml==ans); } -//----------------------------------------------------------------------------------------------------------------------------------------------- -// ignore ! option - - -//----------------------------------------------------------------------------------------------------------------------------------------------- -// TypeConversion +// TEST(yaml, multi_line_str_by_hash_vertical_line_minus_num_2){ // : |-2 +// } -// Note. TypeConversion segment is implemented and tested on terp.cpp/hpp. +// TEST(yaml, multi_line_str_by_hash_vertical_line_plus_num_1){ // : |+1 +// } -// to -// to -// to -// to -// to -// to -// to -// to -// to -// to -// to -// to -// to -// to -// to -// to +// TEST(yaml, multi_line_str_by_hash_vertical_line_plus_num_2){ // : |+2 +// } -//----------------------------------------------------------------------------------------------------------------------------------------------- -// Multi line string for list +//--- -TEST(yaml, multi_line_str_by_list_vertical_line){ // - | +TEST(yaml, multi_line_str_by_hash_greater){ // : > std::string s=R"( -- a # comment -- | +k1: a # comment +k2: > b1 b2 b3 -- c +k3: c )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -480,26 +2632,26 @@ TEST(yaml, multi_line_str_by_list_vertical_line){ // - | //--- sstd::terp::var ans; - ans = sstd::terp::list(3); - ans[0] = "a"; - ans[1] = "b1\nb2\nb3\n"; - ans[2] = "c"; + ans = sstd::terp::hash(); + ans["k1"] = "a"; + ans["k2"] = "b1 b2 b3\n"; + ans["k3"] = "c"; //--- ASSERT_TRUE(yml==ans); } -TEST(yaml, multi_line_str_by_list_vertical_line_minus){ // - |- +TEST(yaml, multi_line_str_by_hash_greater_minus){ // : >- std::string s=R"( -- a # comment -- |- +k1: a # comment +k2: >- b1 b2 b3 -- c +k3: c )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -507,26 +2659,26 @@ TEST(yaml, multi_line_str_by_list_vertical_line_minus){ // - |- //--- sstd::terp::var ans; - ans = sstd::terp::list(3); - ans[0] = "a"; - ans[1] = "b1\nb2\nb3"; - ans[2] = "c"; + ans = sstd::terp::hash(); + ans["k1"] = "a"; + ans["k2"] = "b1 b2 b3"; + ans["k3"] = "c"; //--- ASSERT_TRUE(yml==ans); } -TEST(yaml, multi_line_str_by_list_vertical_line_plus){ // - |+ +TEST(yaml, multi_line_str_by_hash_greater_plus){ // : >+ std::string s=R"( -- a # comment -- |+ +k1: a # comment +k2: >+ b1 b2 b3 -- c +k3: c )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -534,29 +2686,29 @@ TEST(yaml, multi_line_str_by_list_vertical_line_plus){ // - |+ //--- sstd::terp::var ans; - ans = sstd::terp::list(3); - ans[0] = "a"; - ans[1] = "b1\nb2\nb3\n\n\n"; - ans[2] = "c"; + ans = sstd::terp::hash(); + ans["k1"] = "a"; + ans["k2"] = "b1 b2 b3\n\n\n"; + ans["k3"] = "c"; //--- ASSERT_TRUE(yml==ans); } -// TEST(yaml, multi_line_str_by_list_vertical_line_num_0){ // - |0 (Can't set 0. Because of the indent under list struct is equal or larger than 1) +// TEST(yaml, multi_line_str_by_hash_greater_num_0){ // : >0 (Can't set 0. Because of the indent under hash struct is equal or larger than 1) // } -TEST(yaml, multi_line_str_by_list_vertical_line_num_1){ // - |1 +TEST(yaml, multi_line_str_by_hash_greater_num_1){ // : >1 std::string s=R"( -- a # comment -- |1 +k1: a # comment +k2: >1 b1 b2 b3 -- c +k3: c )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -564,83 +2716,107 @@ TEST(yaml, multi_line_str_by_list_vertical_line_num_1){ // - |1 //--- sstd::terp::var ans; - ans = sstd::terp::list(3); - ans[0] = "a"; - ans[1] = " b1\n b2\n b3\n"; - ans[2] = "c"; + ans = sstd::terp::hash(); + ans["k1"] = "a"; + ans["k2"] = " b1\n b2\n b3\n"; + ans["k3"] = "c"; + //sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } -TEST(yaml, multi_line_str_by_list_vertical_line_num_1_case02){ // - |1 +TEST(yaml, multi_line_str_by_hash_greater_num_2){ // : >2 std::string s=R"( -- a # comment -- |1 - b1 +k1: a # comment +k2: >2 + b1 b2 - b3 + b3 -- c +k3: c )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE - //sstd::printn(yml); +// sstd::printn(yml); //--- sstd::terp::var ans; - ans = sstd::terp::list(3); - ans[0] = "a"; - ans[1] = "b1\n b2\nb3\n"; - ans[2] = "c"; + ans = sstd::terp::hash(); + ans["k1"] = "a"; + ans["k2"] = "b1 b2 b3\n"; + ans["k3"] = "c"; //--- ASSERT_TRUE(yml==ans); } -TEST(yaml, multi_line_str_by_list_vertical_line_num_2){ // - |2 - std::string s=R"( -- a # comment -- |2 - b1 - b2 - b3 +// TEST(yaml, multi_line_str_by_hash_greater_minus_num_1){ // : >-1 +// } + +// TEST(yaml, multi_line_str_by_hash_greater_minus_num_2){ // : >-2 +// } -- c +// TEST(yaml, multi_line_str_by_hash_greater_plus_num_1){ // : >+1 +// } + +// TEST(yaml, multi_line_str_by_hash_greater_plus_num_2){ // : >+2 +// } + +//----------------------------------------------------------------------------------------------------------------------------------------------- +// Double quotation "" and Single quotation '' + +TEST(yaml, double_quotation_NUM_STR){ + std::string s=R"( +"a: b c\" + +def +g" )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE - //sstd::printn(yml); +// sstd::printn(yml); //--- sstd::terp::var ans; - ans = sstd::terp::list(3); - ans[0] = "a"; - ans[1] = "b1\nb2\nb3\n"; - ans[2] = "c"; + ans=R"(a: b c" +def g)"; + // "a: b c\"\ndef g" + //sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } +TEST(yaml, double_quotation_NUM_STR_xx){ + std::string s=R"(a -// TEST(yaml, multi_line_str_by_list_vertical_line_minus_num_0){ // - |-0 (Can't set 0. Because of the indent under list struct is equal or larger than 1) -// } +b +c)"; + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE +// sstd::printn(yml); -TEST(yaml, multi_line_str_by_list_vertical_line_minus_num_1){ - std::string s=R"( -- a # comment -- |-1 - b1 - b2 - b3 + //--- + + sstd::terp::var ans; + ans="a\nb c"; + // "a: b c\"\ndef g" + //sstd::printn(ans); + + //--- + + ASSERT_TRUE(yml==ans); +} +//--- -- c +TEST(yaml, double_quotation_list_NUM_LIST_case01){ + std::string s=R"( +- "a: b c " )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -648,54 +2824,42 @@ TEST(yaml, multi_line_str_by_list_vertical_line_minus_num_1){ //--- sstd::terp::var ans; - ans = sstd::terp::list(3); - ans[0] = "a"; - ans[1] = " b1\n b2\n b3"; - ans[2] = "c"; + ans = sstd::terp::list(1); + ans[0] = "a: b c "; + //sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } - -// TEST(yaml, multi_line_str_by_list_vertical_line_plus_num_0){ // - |+0 (Can't set 0. Because of the indent under list struct is equal or larger than 1) -// } - -TEST(yaml, multi_line_str_by_list_vertical_line_plus_num_1){ +TEST(yaml, double_quotation_list_NUM_LIST_case02){ // WIP + // See "5.7. Escaped Characters" at https://yaml.org/spec/1.2.2/#57-escaped-characters + std::string s=R"( -- a # comment -- |+1 - b1 - b2 - b3 - - -- c +- "\ + abc\ + def" )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE - //sstd::printn(yml); + sstd::printn(yml); //--- sstd::terp::var ans; - ans = sstd::terp::list(3); - ans[0] = "a"; - ans[1] = " b1\n b2\n b3\n\n\n"; - ans[2] = "c"; + ans = sstd::terp::list(1); + ans[0] = "abcdef"; + sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } -TEST(yaml, multi_line_str_by_list_vertical_line_with_different_head_spaces__vertical){ +//--- + +TEST(yaml, double_quotation_list_NUM_HASH_dq_case01){ std::string s=R"( -- | - a - b - c - d - e +"key1": "a: b c " )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -703,22 +2867,17 @@ TEST(yaml, multi_line_str_by_list_vertical_line_with_different_head_spaces__vert //--- sstd::terp::var ans; - ans = sstd::terp::list(1); - ans[0] = "a\nb\n c\n d\ne\n"; + ans = sstd::terp::hash(); + ans["key1"] = "a: b c "; //sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } -TEST(yaml, multi_line_str_by_list_vertical_line_with_different_head_spaces__vertical_1){ +TEST(yaml, double_quotation_list_NUM_HASH_dq_case02){ // escape \" and non escape ' std::string s=R"( -- |1 - a - b - c - d - e +"key1 \"'": " a: b c \"' " )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -726,22 +2885,17 @@ TEST(yaml, multi_line_str_by_list_vertical_line_with_different_head_spaces__vert //--- sstd::terp::var ans; - ans = sstd::terp::list(1); - ans[0] = " a\n b\n c\n d\n e\n"; + ans = sstd::terp::hash(); + ans[R"(key1 "')"] = R"( a: b c "' )"; //sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } -TEST(yaml, multi_line_str_by_list_vertical_line_with_different_head_spaces__vertical_minus){ +TEST(yaml, single_quotation_list_NUM_HASH_sq_case01){ std::string s=R"( -- |- - a - b - c - d - e +'key1': 'a: b c ' )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -749,27 +2903,17 @@ TEST(yaml, multi_line_str_by_list_vertical_line_with_different_head_spaces__vert //--- sstd::terp::var ans; - ans = sstd::terp::list(1); - ans[0] = "a\nb\n c\n d\ne"; + ans = sstd::terp::hash(); + ans["key1"] = "a: b c "; //sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } - -//--- - -TEST(yaml, multi_line_str_by_list_greater){ // - > +TEST(yaml, single_quotation_list_NUM_HASH_sq_case02){ // escape \' and non escape " std::string s=R"( -- a # comment -- > - b1 - b2 - b3 - - -- c +'key1 \'"': ' a: b c \'" ' )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -777,26 +2921,20 @@ TEST(yaml, multi_line_str_by_list_greater){ // - > //--- sstd::terp::var ans; - ans = sstd::terp::list(3); - ans[0] = "a"; - ans[1] = "b1 b2 b3\n"; - ans[2] = "c"; + ans = sstd::terp::hash(); + ans["key1 '\""] = " a: b c '\" "; + //sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } -TEST(yaml, multi_line_str_by_list_greater_minus){ // - >- - std::string s=R"( -- a # comment -- >- - b1 - b2 - b3 - +//--- -- c +TEST(yaml, double_quotation_list_NUM_LIST_AND_HASH_dq_case01){ + std::string s=R"( +- "key1": "a: b c " )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -804,26 +2942,18 @@ TEST(yaml, multi_line_str_by_list_greater_minus){ // - >- //--- sstd::terp::var ans; - ans = sstd::terp::list(3); - ans[0] = "a"; - ans[1] = "b1 b2 b3"; - ans[2] = "c"; + ans = sstd::terp::list(1); + ans[0] = sstd::terp::hash(); + ans[0]["key1"] = "a: b c "; + //sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } - -TEST(yaml, multi_line_str_by_list_greater_plus){ // - >+ +TEST(yaml, single_quotation_list_NUM_LIST_AND_HASH_sq_case01){ std::string s=R"( -- a # comment -- >+ - b1 - b2 - b3 - - -- c +- 'key1': 'a: b c ' )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -831,29 +2961,21 @@ TEST(yaml, multi_line_str_by_list_greater_plus){ // - >+ //--- sstd::terp::var ans; - ans = sstd::terp::list(3); - ans[0] = "a"; - ans[1] = "b1 b2 b3\n\n\n"; - ans[2] = "c"; + ans = sstd::terp::list(1); + ans[0] = sstd::terp::hash(); + ans[0]["key1"] = "a: b c "; + //sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } -// TEST(yaml, multi_line_str_by_list_greater_num_0){ // - >0 (Can't set 0. Because of the indent under list struct is equal or larger than 1) -// } +//--- -TEST(yaml, multi_line_str_by_list_greater_num_1){ // - >1 +TEST(yaml, double_quotation_list_case01){ std::string s=R"( -- a # comment -- >1 - b1 - b2 - b3 - - -- c +- "a: b" )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -861,26 +2983,17 @@ TEST(yaml, multi_line_str_by_list_greater_num_1){ // - >1 //--- sstd::terp::var ans; - ans = sstd::terp::list(3); - ans[0] = "a"; - ans[1] = " b1\n b2\n b3\n"; - ans[2] = "c"; + ans = sstd::terp::list(1); + ans[0] = "a: b"; + //sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } -TEST(yaml, multi_line_str_by_list_greater_num_1_case02){ // - >1 +TEST(yaml, double_quotation_list_case02){ std::string s=R"( -- a # comment -- - - >1 - b1 - b2 - b3 - - -- c +- "a b c" )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -888,27 +3001,17 @@ TEST(yaml, multi_line_str_by_list_greater_num_1_case02){ // - >1 //--- sstd::terp::var ans; - ans = sstd::terp::list(3); - ans[0] = "a"; - ans[1] = sstd::terp::list(1); - ans[1][0] = " b1\n b2\n b3\n"; - ans[2] = "c"; + ans = sstd::terp::list(1); + ans[0] = "a b c"; + //sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } - -TEST(yaml, multi_line_str_by_list_greater_num_2){ // - >2 +TEST(yaml, double_quotation_list_case03){ std::string s=R"( -- a # comment -- >2 - b1 - b2 - b3 - - -- c +- "- a" )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -916,27 +3019,17 @@ TEST(yaml, multi_line_str_by_list_greater_num_2){ // - >2 //--- sstd::terp::var ans; - ans = sstd::terp::list(3); - ans[0] = "a"; - ans[1] = "b1 b2 b3\n"; - ans[2] = "c"; + ans = sstd::terp::list(1); + ans[0] = "- a"; + //sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } - -TEST(yaml, multi_line_str_by_list_greater_num_4){ // - >4 +TEST(yaml, double_quotation_list_case04){ std::string s=R"( -- a # comment -- - - >4 - b1 - b2 - b3 - - -- c +" - a " )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -944,27 +3037,20 @@ TEST(yaml, multi_line_str_by_list_greater_num_4){ // - >4 //--- sstd::terp::var ans; - ans = sstd::terp::list(3); - ans[0] = "a"; - ans[1] = sstd::terp::list(1); - ans[1][0] = "b1 b2 b3\n"; - ans[2] = "c"; + ans = " - a "; + //sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } -TEST(yaml, multi_line_str_by_list_greater_minus_num_1){ // - >-1 - std::string s=R"( -- a # comment -- >-1 - b1 - b2 - b3 - +//--- +// NULL case -- c +TEST(yaml, double_quotation_empty_list_case01){ + std::string s=R"( +- "" )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -972,38 +3058,17 @@ TEST(yaml, multi_line_str_by_list_greater_minus_num_1){ // - >-1 //--- sstd::terp::var ans; - ans = sstd::terp::list(3); - ans[0] = "a"; - ans[1] = " b1\n b2\n b3"; - ans[2] = "c"; + ans = sstd::terp::list(1); + ans[0] = ""; + //sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } - -// TEST(yaml, multi_line_str_by_list_greater_minus_num_2){ // - >-2 -// } - -// TEST(yaml, multi_line_str_by_list_greater_plus_num_1){ // - >-1 -// } - -// TEST(yaml, multi_line_str_by_list_greater_plus_num_2){ // - >-2 -// } - -//----------------------------------------------------------------------------------------------------------------------------------------------- -// Multi line string for hash - -TEST(yaml, multi_line_str_by_hash_vertical_line){ // : | +TEST(yaml, double_quotation_empty_list_hash_case01){ std::string s=R"( -k1: a # comment -k2: | - b1 - b2 - b3 - - -k3: c +- "": "" )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -1011,26 +3076,18 @@ k3: c //--- sstd::terp::var ans; - ans = sstd::terp::hash(); - ans["k1"] = "a"; - ans["k2"] = "b1\nb2\nb3\n"; - ans["k3"] = "c"; - - //--- - - ASSERT_TRUE(yml==ans); -} - -TEST(yaml, multi_line_str_by_hash_vertical_line_minus){ // : |- - std::string s=R"( -k1: a # comment -k2: |- - b1 - b2 - b3 - - -k3: c + ans = sstd::terp::list(1); + ans[0] = sstd::terp::hash(); + ans[0][""] = ""; + //sstd::printn(ans); + + //--- + + ASSERT_TRUE(yml==ans); +} +TEST(yaml, double_quotation_empty_hash_case01){ + std::string s=R"( +"": "" )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -1039,25 +3096,23 @@ k3: c sstd::terp::var ans; ans = sstd::terp::hash(); - ans["k1"] = "a"; - ans["k2"] = "b1\nb2\nb3"; - ans["k3"] = "c"; + ans[""] = ""; + //sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } +//*/ +//----------------------------------------------------------------------------------------------------------------------------------------------- +// Complicated test +//* +// Double quotation "" and Single quotation '' -TEST(yaml, multi_line_str_by_hash_vertical_line_plus){ // : |+ +TEST(yaml, double_quotation_complicated_multiline_test_case01){ std::string s=R"( -k1: a # comment -k2: |+ - b1 - b2 - b3 - - -k3: c +- "I am a cat.\ + There is no name yet." )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -1065,29 +3120,18 @@ k3: c //--- sstd::terp::var ans; - ans = sstd::terp::hash(); - ans["k1"] = "a"; - ans["k2"] = "b1\nb2\nb3\n\n\n"; - ans["k3"] = "c"; + ans = sstd::terp::list(1); + ans[0] = "I am a cat.There is no name yet."; + //sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } - -// TEST(yaml, multi_line_str_by_hash_vertical_line_num_0){ // : |0 (Can't set 0. Because of the indent under hash struct is equal or larger than 1) -// } - -TEST(yaml, multi_line_str_by_hash_vertical_line_num_1){ // : |1 +TEST(yaml, double_quotation_complicated_multiline_test_case02){ std::string s=R"( -k1: a # comment -k2: |1 - b1 - b2 - b3 - - -k3: c +- "I am a cat. \ + There is no name yet." )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -1095,26 +3139,18 @@ k3: c //--- sstd::terp::var ans; - ans = sstd::terp::hash(); - ans["k1"] = "a"; - ans["k2"] = " b1\n b2\n b3\n"; - ans["k3"] = "c"; + ans = sstd::terp::list(1); + ans[0] = "I am a cat. There is no name yet."; + //sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } - -TEST(yaml, multi_line_str_by_hash_vertical_line_num_2){ // : |2 +TEST(yaml, double_quotation_complicated_multiline_test_case03){ std::string s=R"( -k1: a # comment -k2: |2 - b1 - b2 - b3 - - -k3: c +- "I am a cat. + There is no name yet." )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -1122,26 +3158,18 @@ k3: c //--- sstd::terp::var ans; - ans = sstd::terp::hash(); - ans["k1"] = "a"; - ans["k2"] = "b1\nb2\nb3\n"; - ans["k3"] = "c"; + ans = sstd::terp::list(1); + ans[0] = "I am a cat. There is no name yet."; + //sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } - -TEST(yaml, multi_line_str_by_hash_vertical_line_minus_num_1){ // : |-1 +TEST(yaml, double_quotation_complicated_multiline_test_case04){ std::string s=R"( -k1: a # comment -k2: |-1 - b1 - b2 - b3 - - -k3: c +- "I am a cat. + There is no name yet." )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -1149,37 +3177,18 @@ k3: c //--- sstd::terp::var ans; - ans = sstd::terp::hash(); - ans["k1"] = "a"; - ans["k2"] = " b1\n b2\n b3"; - ans["k3"] = "c"; + ans = sstd::terp::list(1); + ans[0] = "I am a cat. There is no name yet."; + //sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } - -// TEST(yaml, multi_line_str_by_hash_vertical_line_minus_num_2){ // : |-2 -// } - -// TEST(yaml, multi_line_str_by_hash_vertical_line_plus_num_1){ // : |+1 -// } - -// TEST(yaml, multi_line_str_by_hash_vertical_line_plus_num_2){ // : |+2 -// } - -//--- - -TEST(yaml, multi_line_str_by_hash_greater){ // : > +TEST(yaml, double_quotation_complicated_multiline_test_case05){ std::string s=R"( -k1: a # comment -k2: > - b1 - b2 - b3 - - -k3: c +- "I am a cat. + There is no name yet." )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -1187,26 +3196,18 @@ k3: c //--- sstd::terp::var ans; - ans = sstd::terp::hash(); - ans["k1"] = "a"; - ans["k2"] = "b1 b2 b3\n"; - ans["k3"] = "c"; + ans = sstd::terp::list(1); + ans[0] = "I am a cat. There is no name yet."; + //sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } - -TEST(yaml, multi_line_str_by_hash_greater_minus){ // : >- +TEST(yaml, double_quotation_complicated_multiline_test_case06){ std::string s=R"( -k1: a # comment -k2: >- - b1 - b2 - b3 - - -k3: c +- "I am a cat. \ + There is no name yet." )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -1214,26 +3215,18 @@ k3: c //--- sstd::terp::var ans; - ans = sstd::terp::hash(); - ans["k1"] = "a"; - ans["k2"] = "b1 b2 b3"; - ans["k3"] = "c"; + ans = sstd::terp::list(1); + ans[0] = "I am a cat. There is no name yet."; + //sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } - -TEST(yaml, multi_line_str_by_hash_greater_plus){ // : >+ +TEST(yaml, double_quotation_complicated_multiline_test_case07){ std::string s=R"( -k1: a # comment -k2: >+ - b1 - b2 - b3 - - -k3: c +- " I am a cat. + There is no name yet." )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -1241,29 +3234,21 @@ k3: c //--- sstd::terp::var ans; - ans = sstd::terp::hash(); - ans["k1"] = "a"; - ans["k2"] = "b1 b2 b3\n\n\n"; - ans["k3"] = "c"; + ans = sstd::terp::list(1); + ans[0] = " I am a cat. There is no name yet."; + //sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } - -// TEST(yaml, multi_line_str_by_hash_greater_num_0){ // : >0 (Can't set 0. Because of the indent under hash struct is equal or larger than 1) -// } - -TEST(yaml, multi_line_str_by_hash_greater_num_1){ // : >1 +TEST(yaml, double_quotation_complicated_multiline_test_case08){ std::string s=R"( -k1: a # comment -k2: >1 - b1 - b2 - b3 - - -k3: c +- " I am a cat. + + + + There is no name yet. " )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -1271,27 +3256,19 @@ k3: c //--- sstd::terp::var ans; - ans = sstd::terp::hash(); - ans["k1"] = "a"; - ans["k2"] = " b1\n b2\n b3\n"; - ans["k3"] = "c"; + ans = sstd::terp::list(1); + ans[0] = " I am a cat.\n\n\nThere is no name yet. "; //sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } - -TEST(yaml, multi_line_str_by_hash_greater_num_2){ // : >2 +TEST(yaml, double_quotation_complicated_multiline_test_case09){ std::string s=R"( -k1: a # comment -k2: >2 - b1 - b2 - b3 - - -k3: c +- "\ + I am a cat.\ + There is no name yet." )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -1299,38 +3276,19 @@ k3: c //--- sstd::terp::var ans; - ans = sstd::terp::hash(); - ans["k1"] = "a"; - ans["k2"] = "b1 b2 b3\n"; - ans["k3"] = "c"; + ans = sstd::terp::list(1); + ans[0] = "I am a cat.There is no name yet."; + //sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } - -// TEST(yaml, multi_line_str_by_hash_greater_minus_num_1){ // : >-1 -// } - -// TEST(yaml, multi_line_str_by_hash_greater_minus_num_2){ // : >-2 -// } - - -// TEST(yaml, multi_line_str_by_hash_greater_plus_num_1){ // : >+1 -// } - -// TEST(yaml, multi_line_str_by_hash_greater_plus_num_2){ // : >+2 -// } - -//----------------------------------------------------------------------------------------------------------------------------------------------- -// Double quotation "" and Single quotation '' - -TEST(yaml, double_quotation_NUM_STR){ +TEST(yaml, double_quotation_complicated_multiline_test_case10){ std::string s=R"( -"a: b c\" - -def -g" +- " + I am a cat.\ + There is no name yet." )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -1338,20 +3296,19 @@ g" //--- sstd::terp::var ans; - ans=R"(a: b c" -def g)"; + ans = sstd::terp::list(1); + ans[0] = " I am a cat.There is no name yet."; //sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } - -//--- - -TEST(yaml, double_quotation_list_NUM_LIST_case01){ +TEST(yaml, double_quotation_complicated_multiline_test_case11){ std::string s=R"( -- "a: b c " +- " \ + I am a cat.\ + There is no name yet." )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -1360,18 +3317,21 @@ TEST(yaml, double_quotation_list_NUM_LIST_case01){ sstd::terp::var ans; ans = sstd::terp::list(1); - ans[0] = "a: b c "; + ans[0] = " I am a cat.There is no name yet."; //sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } -TEST(yaml, double_quotation_list_NUM_LIST_case02){ // WIP + +//--- + +TEST(yaml, double_quotation_complicated_multiline_test_case12){ std::string s=R"( -- "\ - abc\ - def" +- key1: "\ + I am a cat.\ + There is no name yet." )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -1380,94 +3340,128 @@ TEST(yaml, double_quotation_list_NUM_LIST_case02){ // WIP sstd::terp::var ans; ans = sstd::terp::list(1); - ans[0] = "abcdef"; + ans[0] = sstd::terp::hash(); + ans[0]["key1"] = "I am a cat.There is no name yet."; //sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } - -//--- - -TEST(yaml, double_quotation_list_NUM_HASH_dq_case01){ +//*/ +//----------------------------------------------------------------------------------------------------------------------------------------------- +// Multipul list indication +//* +TEST(yaml, multipul_list_indication_case01){ std::string s=R"( -"key1": "a: b c " +- - a +#- +# - a )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE - //sstd::printn(yml); +// sstd::printn(yml); //--- sstd::terp::var ans; - ans = sstd::terp::hash(); - ans["key1"] = "a: b c "; - //sstd::printn(ans); + ans = sstd::terp::list(1); + ans[0] = sstd::terp::list(1); + ans[0][0] = "a"; +// sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } -TEST(yaml, double_quotation_list_NUM_HASH_dq_case02){ // escape \" and non escape ' +TEST(yaml, multipul_list_indication_case02a){ std::string s=R"( -"key1 \"'": " a: b c \"' " +- - - a + - b +#- +# - +# - a +# - b )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE - //sstd::printn(yml); +// sstd::printn(yml); //--- sstd::terp::var ans; - ans = sstd::terp::hash(); - ans[R"(key1 "')"] = R"( a: b c "' )"; - //sstd::printn(ans); + ans = sstd::terp::list(1); + ans[0] = sstd::terp::list(2); + ans[0][0] = sstd::terp::list(1); + ans[0][0][0] = "a"; + ans[0][1] = "b"; +// sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } -TEST(yaml, single_quotation_list_NUM_HASH_sq_case01){ +TEST(yaml, multipul_list_indication_case02b){ std::string s=R"( -'key1': 'a: b c ' +#- - - a +# - b +- + - + - a + - b )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE - //sstd::printn(yml); +// sstd::printn(yml); //--- sstd::terp::var ans; - ans = sstd::terp::hash(); - ans["key1"] = "a: b c "; - //sstd::printn(ans); + ans = sstd::terp::list(1); + ans[0] = sstd::terp::list(2); + ans[0][0] = sstd::terp::list(1); + ans[0][0][0] = "a"; + ans[0][1] = "b"; +// sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } -TEST(yaml, single_quotation_list_NUM_HASH_sq_case02){ // escape \' and non escape " +TEST(yaml, multipul_list_indication_case03){ std::string s=R"( -'key1 \'"': ' a: b c \'" ' +- - - k1: v1 + - k2: v2 +#- +# - +# - k1: v1 +# - k2: v2 )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE - //sstd::printn(yml); +// sstd::printn(yml); //--- sstd::terp::var ans; - ans = sstd::terp::hash(); - ans["key1 '\""] = " a: b c '\" "; - //sstd::printn(ans); + ans = sstd::terp::list(1); + ans[0] = sstd::terp::list(2); + ans[0][0] = sstd::terp::list(1); + ans[0][0][0] = sstd::terp::hash(); + ans[0][0][0]["k1"] = "v1"; + ans[0][1] = sstd::terp::hash(); + ans[0][1]["k2"] = "v2"; +// sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } - -//--- - -TEST(yaml, double_quotation_list_NUM_LIST_AND_HASH_dq_case01){ +TEST(yaml, multipul_list_indication_case04){ std::string s=R"( -- "key1": "a: b c " +- + - a + - - b # TEST THIS LINE +#- +# - a +# - +# - b # TEST THIS LINE )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -1476,17 +3470,22 @@ TEST(yaml, double_quotation_list_NUM_LIST_AND_HASH_dq_case01){ sstd::terp::var ans; ans = sstd::terp::list(1); - ans[0] = sstd::terp::hash(); - ans[0]["key1"] = "a: b c "; + ans[0] = sstd::terp::list(2); + ans[0][0] = "a"; + ans[0][1] = sstd::terp::list(1); + ans[0][1][0] = "b"; //sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } -TEST(yaml, single_quotation_list_NUM_LIST_AND_HASH_sq_case01){ +TEST(yaml, multipul_list_indication_case05){ std::string s=R"( -- 'key1': 'a: b c ' +- - - a +#- +# - +# - a )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -1495,20 +3494,25 @@ TEST(yaml, single_quotation_list_NUM_LIST_AND_HASH_sq_case01){ sstd::terp::var ans; ans = sstd::terp::list(1); - ans[0] = sstd::terp::hash(); - ans[0]["key1"] = "a: b c "; + ans[0] = sstd::terp::list(1); + ans[0][0] = sstd::terp::list(1); + ans[0][0][0] = "a"; //sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } - -//--- - -TEST(yaml, double_quotation_list_case01){ +TEST(yaml, multipul_list_indication_case06){ std::string s=R"( -- "a: b" +- - a + - - - - b +#- +# - a +# - +# - +# - +# - b )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -1517,16 +3521,21 @@ TEST(yaml, double_quotation_list_case01){ sstd::terp::var ans; ans = sstd::terp::list(1); - ans[0] = "a: b"; + ans[0] = sstd::terp::list(2); + ans[0][0] = "a"; + ans[0][1] = sstd::terp::list(1); + ans[0][1][0] = sstd::terp::list(1); + ans[0][1][0][0] = sstd::terp::list(1); + ans[0][1][0][0][0] = "b"; //sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } -TEST(yaml, double_quotation_list_case02){ +TEST(yaml, multipul_list_indication_case07){ std::string s=R"( -- "a b c" +- - key1: val1 )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -1535,16 +3544,26 @@ TEST(yaml, double_quotation_list_case02){ sstd::terp::var ans; ans = sstd::terp::list(1); - ans[0] = "a b c"; + ans[0] = sstd::terp::list(1); + ans[0][0] = sstd::terp::hash(); + ans[0][0]["key1"] = "val1"; //sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } -TEST(yaml, double_quotation_list_case03){ +TEST(yaml, multipul_list_indication_case08){ std::string s=R"( -- "- a" +- a +- b +- - c1 + - c2 + - c3 +- - d1: d2 +- - - - e1 + - e2 + - e3 )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -1552,21 +3571,37 @@ TEST(yaml, double_quotation_list_case03){ //--- sstd::terp::var ans; - ans = sstd::terp::list(1); - ans[0] = "- a"; + ans = sstd::terp::list(5); + ans[0] = "a"; + ans[1] = "b"; + ans[2] = sstd::terp::list(3); + ans[2][0] = "c1"; + ans[2][1] = "c2"; + ans[2][2] = "c3"; + ans[3] = sstd::terp::list(1); + ans[3][0] = sstd::terp::hash(); + ans[3][0]["d1"] = "d2"; + ans[4] = sstd::terp::list(1); + ans[4][0] = sstd::terp::list(1); + ans[4][0][0] = sstd::terp::list(3); + ans[4][0][0][0] = "e1"; + ans[4][0][0][1] = "e2"; + ans[4][0][0][2] = "e3"; //sstd::printn(ans); //--- ASSERT_TRUE(yml==ans); } +//*/ +//----------------------------------------------------------------------------------------------------------------------------------------------- +// flow style notation //--- -// NULL case - -TEST(yaml, double_quotation_empty_list_case01){ +//* +TEST(yaml, block_list_and_flow_list){ std::string s=R"( -- "" +- [a, b, c] )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -1575,16 +3610,19 @@ TEST(yaml, double_quotation_empty_list_case01){ sstd::terp::var ans; ans = sstd::terp::list(1); - ans[0] = ""; + ans[0] = sstd::terp::list(3); + ans[0][0] = "a"; + ans[0][1] = "b"; + ans[0][2] = "c"; //sstd::printn(ans); - + //--- ASSERT_TRUE(yml==ans); } -TEST(yaml, double_quotation_empty_list_hash_case01){ +TEST(yaml, block_list_and_flow_hash){ std::string s=R"( -- "": "" +- {k1:v1, k2:v2, k3:v3} )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -1594,16 +3632,18 @@ TEST(yaml, double_quotation_empty_list_hash_case01){ sstd::terp::var ans; ans = sstd::terp::list(1); ans[0] = sstd::terp::hash(); - ans[0][""] = ""; + ans[0]["k1"] = "v1"; + ans[0]["k2"] = "v2"; + ans[0]["k3"] = "v3"; //sstd::printn(ans); - + //--- ASSERT_TRUE(yml==ans); } -TEST(yaml, double_quotation_empty_hash_case01){ +TEST(yaml, block_hash_and_flow_list){ std::string s=R"( -"": "" +k1: [a, b, c] )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -1612,23 +3652,25 @@ TEST(yaml, double_quotation_empty_hash_case01){ sstd::terp::var ans; ans = sstd::terp::hash(); - ans[""] = ""; + ans["k1"] = sstd::terp::list(3); + ans["k1"][0] = "a"; + ans["k1"][1] = "b"; + ans["k1"][2] = "c"; //sstd::printn(ans); - + //--- ASSERT_TRUE(yml==ans); } +TEST(yaml, block_hash_and_flow_hash){} +TEST(yaml, block_list_hash_and_flow_list){} +TEST(yaml, block_list_hash_and_flow_hash){} -//----------------------------------------------------------------------------------------------------------------------------------------------- -// Complicated test - -// Double quotation "" and Single quotation '' +//--- -TEST(yaml, double_quotation_complicated_multiline_test_case01){ +TEST(yaml, flow_style_notation_list_01){ std::string s=R"( -- "I am a cat.\ - There is no name yet." +[a, b, c] )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -1636,18 +3678,19 @@ TEST(yaml, double_quotation_complicated_multiline_test_case01){ //--- sstd::terp::var ans; - ans = sstd::terp::list(1); - ans[0] = "I am a cat.There is no name yet."; + ans = sstd::terp::list(3); + ans[0] = "a"; + ans[1] = "b"; + ans[2] = "c"; //sstd::printn(ans); - + //--- ASSERT_TRUE(yml==ans); } -TEST(yaml, double_quotation_complicated_multiline_test_case02){ +TEST(yaml, flow_style_notation_list_02){ std::string s=R"( -- "I am a cat. \ - There is no name yet." +[a, [b], c, [d, [e]], f] )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -1655,18 +3698,25 @@ TEST(yaml, double_quotation_complicated_multiline_test_case02){ //--- sstd::terp::var ans; - ans = sstd::terp::list(1); - ans[0] = "I am a cat. There is no name yet."; + ans = sstd::terp::list(5); + ans[0] = "a"; + ans[1] = sstd::terp::list(1); + ans[1][0] = "b"; + ans[2] = "c"; + ans[3] = sstd::terp::list(2); + ans[3][0] = "d"; + ans[3][1] = sstd::terp::list(1); + ans[3][1][0] = "e"; + ans[4] = "f"; //sstd::printn(ans); - + //--- ASSERT_TRUE(yml==ans); } -TEST(yaml, double_quotation_complicated_multiline_test_case03){ +TEST(yaml, flow_style_notation_hash_01){ std::string s=R"( -- "I am a cat. - There is no name yet." +{k1: v1} )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -1674,18 +3724,17 @@ TEST(yaml, double_quotation_complicated_multiline_test_case03){ //--- sstd::terp::var ans; - ans = sstd::terp::list(1); - ans[0] = "I am a cat. There is no name yet."; + ans = sstd::terp::hash(); + ans["k1"] = "v1"; //sstd::printn(ans); - + //--- ASSERT_TRUE(yml==ans); } -TEST(yaml, double_quotation_complicated_multiline_test_case04){ +TEST(yaml, flow_style_notation_hash_02){ std::string s=R"( -- "I am a cat. - There is no name yet." +{k1: v1, k2: v2} )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -1693,18 +3742,18 @@ TEST(yaml, double_quotation_complicated_multiline_test_case04){ //--- sstd::terp::var ans; - ans = sstd::terp::list(1); - ans[0] = "I am a cat. There is no name yet."; + ans = sstd::terp::hash(); + ans["k1"] = "v1"; + ans["k2"] = "v2"; //sstd::printn(ans); - + //--- ASSERT_TRUE(yml==ans); } -TEST(yaml, double_quotation_complicated_multiline_test_case05){ +TEST(yaml, flow_style_notation_hash_03){ std::string s=R"( -- "I am a cat. - There is no name yet." +{k1: {k11: v11}} )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -1712,18 +3761,18 @@ TEST(yaml, double_quotation_complicated_multiline_test_case05){ //--- sstd::terp::var ans; - ans = sstd::terp::list(1); - ans[0] = "I am a cat. There is no name yet."; + ans = sstd::terp::hash(); + ans["k1"] = sstd::terp::hash();; + ans["k1"]["k11"] = "v11"; //sstd::printn(ans); - + //--- ASSERT_TRUE(yml==ans); } -TEST(yaml, double_quotation_complicated_multiline_test_case06){ +TEST(yaml, flow_style_notation_hash_04){ std::string s=R"( -- "I am a cat. \ - There is no name yet." +{k1: {k11: {k111: v111}}, k2:v2} )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -1731,18 +3780,38 @@ TEST(yaml, double_quotation_complicated_multiline_test_case06){ //--- sstd::terp::var ans; - ans = sstd::terp::list(1); - ans[0] = "I am a cat. There is no name yet."; + ans = sstd::terp::hash(); + ans["k1"] = sstd::terp::hash(); + ans["k1"]["k11"] = sstd::terp::hash(); + ans["k1"]["k11"]["k111"] = "v111"; + ans["k2"] = "v2"; //sstd::printn(ans); + + //--- + + ASSERT_TRUE(yml==ans); +} +TEST(yaml, flow_style_notation_hash_null_01){ + std::string s=R"( +{k1} +)"; + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE + //sstd::printn(yml); + + //--- + sstd::terp::var ans; + ans = sstd::terp::hash(); + ans["k1"]; + //sstd::printn(ans); + //--- ASSERT_TRUE(yml==ans); } -TEST(yaml, double_quotation_complicated_multiline_test_case07){ +TEST(yaml, flow_style_notation_hash_null_02){ std::string s=R"( -- " I am a cat. - There is no name yet." +{k1:, k2} )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -1750,61 +3819,86 @@ TEST(yaml, double_quotation_complicated_multiline_test_case07){ //--- sstd::terp::var ans; - ans = sstd::terp::list(1); - ans[0] = " I am a cat. There is no name yet."; + ans = sstd::terp::hash(); + ans["k1"]; + ans["k2"]; //sstd::printn(ans); - + //--- ASSERT_TRUE(yml==ans); } -TEST(yaml, double_quotation_complicated_multiline_test_case08){ +TEST(yaml, flow_style_notation_hash_without_value_01){ std::string s=R"( -- " I am a cat. - - - - There is no name yet. " +- {k1} +- {k2:} +- {k3,k4} +- {k5,k6:,k7} )"; - sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE - //sstd::printn(yml); + sstd::terp::var yml; + bool ret = sstd::yaml_load(yml, s); // TEST THIS LINE +// sstd::printn(yml); //--- sstd::terp::var ans; - ans = sstd::terp::list(1); - ans[0] = " I am a cat.\n\n\nThere is no name yet. "; - //sstd::printn(ans); - + ans = sstd::terp::list(4); + ans[0] = sstd::terp::hash(); + ans[0]["k1"]; + ans[1] = sstd::terp::hash(); + ans[1]["k2"]; + ans[2] = sstd::terp::hash(); + ans[2]["k3"]; + ans[2]["k4"]; + ans[3] = sstd::terp::hash(); + ans[3]["k5"]; + ans[3]["k6"]; + ans[3]["k7"]; +// sstd::printn(ans); + //--- + ASSERT_TRUE(ret); ASSERT_TRUE(yml==ans); } -TEST(yaml, double_quotation_complicated_multiline_test_case09){ +TEST(yaml, flow_style_notation_hash_without_value_01b){ std::string s=R"( -- "\ - I am a cat.\ - There is no name yet." +[{k1},{k2:},{k3,k4},{k5,k6:,k7}] )"; - sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE - //sstd::printn(yml); + sstd::terp::var yml; + bool ret = sstd::yaml_load(yml, s); // TEST THIS LINE +// sstd::printn(yml); //--- sstd::terp::var ans; - ans = sstd::terp::list(1); - ans[0] = "I am a cat.There is no name yet."; - //sstd::printn(ans); - + ans = sstd::terp::list(4); + ans[0] = sstd::terp::hash(); + ans[0]["k1"]; + ans[1] = sstd::terp::hash(); + ans[1]["k2"]; + ans[2] = sstd::terp::hash(); + ans[2]["k3"]; + ans[2]["k4"]; + ans[3] = sstd::terp::hash(); + ans[3]["k5"]; + ans[3]["k6"]; + ans[3]["k7"]; +// sstd::printn(ans); + //--- + ASSERT_TRUE(ret); ASSERT_TRUE(yml==ans); } -TEST(yaml, double_quotation_complicated_multiline_test_case10){ + +//--- + +TEST(yaml, flow_style_notation_list_multiline){ std::string s=R"( -- " - I am a cat.\ - There is no name yet." +[a, +b +, c] )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -1812,19 +3906,20 @@ TEST(yaml, double_quotation_complicated_multiline_test_case10){ //--- sstd::terp::var ans; - ans = sstd::terp::list(1); - ans[0] = " I am a cat.There is no name yet."; + ans = sstd::terp::list(3); + ans[0] = "a"; + ans[1] = "b"; + ans[2] = "c"; //sstd::printn(ans); - + //--- ASSERT_TRUE(yml==ans); } -TEST(yaml, double_quotation_complicated_multiline_test_case11){ +TEST(yaml, flow_style_notation_hash_multiline){ std::string s=R"( -- " \ - I am a cat.\ - There is no name yet." +{k: +v} )"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -1832,10 +3927,10 @@ TEST(yaml, double_quotation_complicated_multiline_test_case11){ //--- sstd::terp::var ans; - ans = sstd::terp::list(1); - ans[0] = " I am a cat.There is no name yet."; + ans = sstd::terp::hash(); + ans["k"] = "v"; //sstd::printn(ans); - + //--- ASSERT_TRUE(yml==ans); @@ -1843,136 +3938,113 @@ TEST(yaml, double_quotation_complicated_multiline_test_case11){ //--- -TEST(yaml, double_quotation_complicated_multiline_test_case12){ - std::string s=R"( -- key1: "\ - I am a cat.\ - There is no name yet." -)"; +TEST(yaml, flow_style_notation_list_hash){ + std::string s=R"([a, {k:v}])"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); //--- sstd::terp::var ans; - ans = sstd::terp::list(1); - ans[0] = sstd::terp::hash(); - ans[0]["key1"] = "I am a cat.There is no name yet."; + ans = sstd::terp::list(2); + ans[0] = "a"; + ans[1] = sstd::terp::hash(); + ans[1]["k"] = "v"; //sstd::printn(ans); - + //--- ASSERT_TRUE(yml==ans); } - -//----------------------------------------------------------------------------------------------------------------------------------------------- -// Multipul list indication - -TEST(yaml, multipul_list_indication_case01){ - std::string s=R"( -- - a -#- -# - a -)"; +TEST(yaml, flow_style_notation_list_hash_02){ + std::string s=R"([a, b, c, {k: v}])"; + //std::string s=R"([a, b, c, [k]])"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); //--- sstd::terp::var ans; - ans = sstd::terp::list(1); - ans[0] = sstd::terp::list(1); - ans[0][0] = "a"; + ans = sstd::terp::list(4); + ans[0] = "a"; + ans[1] = "b"; + ans[2] = "c"; + ans[3] = sstd::terp::hash(); + ans[3]["k"] = "v"; //sstd::printn(ans); - + //--- ASSERT_TRUE(yml==ans); } -TEST(yaml, multipul_list_indication_case02){ - std::string s=R"( -- - - a - - - b # TEST THIS LINE -#- -# - a -# - -# - b # TEST THIS LINE -)"; +TEST(yaml, flow_style_notation_list_hash_03){ + std::string s=R"([a,b,{k:v},c])"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); //--- sstd::terp::var ans; - ans = sstd::terp::list(1); - ans[0] = sstd::terp::list(2); - ans[0][0] = "a"; - ans[0][1] = sstd::terp::list(1); - ans[0][1][0] = "b"; + ans = sstd::terp::list(4); + ans[0] = "a"; + ans[1] = "b"; + ans[2] = sstd::terp::hash(); + ans[2]["k"] = "v"; + ans[3] = "c"; //sstd::printn(ans); - + //--- ASSERT_TRUE(yml==ans); } -TEST(yaml, multipul_list_indication_case03){ - std::string s=R"( -- - - a -#- -# - -# - a -)"; + +TEST(yaml, flow_style_notation_hash_list){ + std::string s=R"({k:[a,b,c]})"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); //--- sstd::terp::var ans; - ans = sstd::terp::list(1); - ans[0] = sstd::terp::list(1); - ans[0][0] = sstd::terp::list(1); - ans[0][0][0] = "a"; + ans = sstd::terp::hash(); + ans["k"] = sstd::terp::list(3); + ans["k"][0] = "a"; + ans["k"][1] = "b"; + ans["k"][2] = "c"; //sstd::printn(ans); - + //--- ASSERT_TRUE(yml==ans); } -TEST(yaml, multipul_list_indication_case04){ - std::string s=R"( -- - a - - - - - b -#- -# - a -# - -# - -# - -# - b -)"; + +TEST(yaml, flow_style_notation_hash_multiline_str){ + std::string s=R"({k: "a + b + c "})"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); //--- sstd::terp::var ans; - ans = sstd::terp::list(1); - ans[0] = sstd::terp::list(2); - ans[0][0] = "a"; - ans[0][1] = sstd::terp::list(1); - ans[0][1][0] = sstd::terp::list(1); - ans[0][1][0][0] = sstd::terp::list(1); - ans[0][1][0][0][0] = "b"; + ans = sstd::terp::hash(); + ans["k"] = "a b c "; //sstd::printn(ans); - + //--- ASSERT_TRUE(yml==ans); } -TEST(yaml, multipul_list_indication_case05){ - std::string s=R"( -- - key1: val1 -)"; + +//--- + +// following 2 notations are same meaning +// +// [k: v] +// [{k: v}] +TEST(yaml, flow_style_notation_list_hash_type1){ + std::string s=R"([{k: v}])"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); @@ -1980,59 +4052,119 @@ TEST(yaml, multipul_list_indication_case05){ sstd::terp::var ans; ans = sstd::terp::list(1); - ans[0] = sstd::terp::list(1); - ans[0][0] = sstd::terp::hash(); - ans[0][0]["key1"] = "val1"; + ans[0] = sstd::terp::hash(); + ans[0]["k"] = "v"; //sstd::printn(ans); - + //--- ASSERT_TRUE(yml==ans); } -TEST(yaml, multipul_list_indication_case06){ - std::string s=R"( -- a -- b -- - c1 - - c2 - - c3 -- - d1: d2 -- - - - e1 - - e2 - - e3 -)"; +TEST(yaml, flow_style_notation_list_hash_type2_Abbreviated){ // NOT SUPPORTED YET + std::string s=R"([k: v])"; sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE //sstd::printn(yml); //--- sstd::terp::var ans; - ans = sstd::terp::list(5); - ans[0] = "a"; - ans[1] = "b"; - ans[2] = sstd::terp::list(3); - ans[2][0] = "c1"; - ans[2][1] = "c2"; - ans[2][2] = "c3"; - ans[3] = sstd::terp::list(1); - ans[3][0] = sstd::terp::hash(); - ans[3][0]["d1"] = "d2"; - ans[4] = sstd::terp::list(1); - ans[4][0] = sstd::terp::list(1); - ans[4][0][0] = sstd::terp::list(3); - ans[4][0][0][0] = "e1"; - ans[4][0][0][1] = "e2"; - ans[4][0][0][2] = "e3"; + ans = sstd::terp::list(1); + ans[0] = sstd::terp::hash(); + ans[0]["k"] = "v"; //sstd::printn(ans); - + //--- ASSERT_TRUE(yml==ans); } +//--- + +//--- +// Tests for sstd::yaml_load_all() + +TEST(yaml, flow_style_notation_hash__for__yaml_load_all){ + std::string s=R"( +{k1: v1} +--- +{k2:v2} +)"; + std::vector vYml; ASSERT_TRUE(sstd::yaml_load_all(vYml, s)); // TEST THIS LINE + //sstd::printn(vYml); + + //--- + + sstd::terp::var ans1; + ans1 = sstd::terp::hash(); + ans1["k1"] = "v1"; + + sstd::terp::var ans2; + ans2 = sstd::terp::hash(); + ans2["k2"] = "v2"; + + //--- + + ASSERT_EQ(vYml.size(), (uint)2); + ASSERT_TRUE(vYml[0]==ans1); + ASSERT_TRUE(vYml[1]==ans2); +} +TEST(yaml, flow_style_notation_list_hash__for__yaml_load_all){ + std::string s=R"( +[a1, b1, c1, {k1: v1}] +--- +[a2, b2, c2, {k2:v2}] +)"; + std::vector vYml; ASSERT_TRUE(sstd::yaml_load_all(vYml, s)); // TEST THIS LINE + //sstd::printn(vYml); + + //--- + + sstd::terp::var ans1; + ans1 = sstd::terp::list(4); + ans1[0] = "a1"; + ans1[1] = "b1"; + ans1[2] = "c1"; + ans1[3] = sstd::terp::hash(); + ans1[3]["k1"] = "v1"; + + sstd::terp::var ans2; + ans2 = sstd::terp::list(4); + ans2[0] = "a2"; + ans2[1] = "b2"; + ans2[2] = "c2"; + ans2[3] = sstd::terp::hash(); + ans2[3]["k2"] = "v2"; + + //--- + + ASSERT_EQ(vYml.size(), (uint)2); + ASSERT_TRUE(vYml[0]==ans1); + ASSERT_TRUE(vYml[1]==ans2); +}/* +TEST(yaml, flow_style_notation_hash__for__yaml_load_all__error01__WIP){ + std::string s=R"( +{k1: v1 +#--- +#{k2:v2} +)"; + //std::vector vYml; ASSERT_TRUE(sstd::yaml_load_all(vYml, s)); // TEST THIS LINE + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE + sstd::printn(yml); +} +TEST(yaml, flow_style_notation_hash__for__yaml_load_all__error02__WIP){ + std::string s=R"( +{k1: v1} +#--- +{k2:v2 +)"; + //std::vector vYml; ASSERT_TRUE(sstd::yaml_load_all(vYml, s)); // TEST THIS LINE + sstd::terp::var yml; ASSERT_TRUE(sstd::yaml_load(yml, s)); // TEST THIS LINE + sstd::printn(yml); +} +*/ //----------------------------------------------------------------------------------------------------------------------------------------------- // End marker ... - +//* TEST(yaml, end_marker){ std::string s=R"( - a # comment @@ -2056,10 +4188,10 @@ TEST(yaml, end_marker){ ASSERT_TRUE(yml==ans); } - +//*/ //----------------------------------------------------------------------------------------------------------------------------------------------- // Split file --- - +//* TEST(yaml, yaml_load_all){ std::string s=R"( - a1 # comment @@ -2153,7 +4285,7 @@ TEST(yaml, yaml_load_all_fp){ ASSERT_TRUE(vYml[0]==ans1); ASSERT_TRUE(vYml[1]==ans2); } - +//*/ //----------------------------------------------------------------------------------------------------------------------------------------------- EXECUTE_TESTS(); diff --git a/test/src_test/memory/terp/terp.cpp b/test/src_test/memory/terp/terp.cpp index 9bbaaefa..04dd0e89 100644 --- a/test/src_test/memory/terp/terp.cpp +++ b/test/src_test/memory/terp/terp.cpp @@ -3,7 +3,7 @@ //----------------------------------------------------------------------------------------------------------------------------------------------- // sstd::terp::var -//* + TEST(memory_terp, var_constructor){ sstd::terp::var a; } @@ -51,10 +51,22 @@ TEST(memory_terp, var_typeStr_c){ a = "test"; ASSERT_STREQ(a.typeStr().c_str(), "str"); // TEST THIS LINE } -//*/ + +//----------------------------------------------------------------------------------------------------------------------------------------------- +// common + +// to +TEST(memory_terp, to_SEGV_null_ptr){ + sstd::terp::var a; + a = sstd::terp::list(1); + + testing::internal::CaptureStdout(); + a[0].to(); // TEST THIS LINE + ASSERT_TRUE(sstd::strIn("NULL pointer is detected", testing::internal::GetCapturedStdout())); +} + //----------------------------------------------------------------------------------------------------------------------------------------------- // sstd::terp::list -//* // operator= TEST(memory_terp, list_ope_assign){ // Ope= @@ -203,6 +215,12 @@ TEST(memory_terp, list_pop_back){ ASSERT_STREQ(a[0].to().c_str(), "v0"); ASSERT_STREQ(a[1].to().c_str(), "v1"); } +TEST(memory_terp, list_pop_back_avoid_SEGV_0_size){ + sstd::terp::var a; + a = sstd::terp::list(); + + a.pop_back(); // TEST THIS LINE +} // push_back() TEST(memory_terp, list_push_back_c){ @@ -212,7 +230,7 @@ TEST(memory_terp, list_push_back_c){ ASSERT_STREQ(a[0].to().c_str(), "test"); } -TEST(memory_terp, list_push_back_list){ +TEST(memory_terp, list_push_back_var_list){ // - // - v1 // - v2 @@ -220,12 +238,61 @@ TEST(memory_terp, list_push_back_list){ sstd::terp::var a; a = sstd::terp::list(); a.push_back(sstd::terp::list()); // TEST THIS LINE + a[0] = sstd::terp::list(); a[0].push_back("v1"); a[0].push_back("v2"); ASSERT_STREQ(a[0][0].to().c_str(), "v1"); ASSERT_STREQ(a[0][1].to().c_str(), "v2"); } +TEST(memory_terp, list_push_back_var_avoid_SEGV_null_ptr){ + sstd::terp::var a; + a = sstd::terp::list(1); + + testing::internal::CaptureStdout(); + a[0].push_back(""); // TEST THIS LINE + ASSERT_TRUE(sstd::strIn("NULL pointer is detected", testing::internal::GetCapturedStdout())); +} +TEST(memory_terp, list_push_back_var_avoid_SEGV_push_back_var){ + sstd::terp::var a, tmp; + a = sstd::terp::list(1); + + testing::internal::CaptureStdout(); + a[0].push_back(tmp); // TEST THIS LINE + ASSERT_TRUE(sstd::strIn("NULL pointer is detected", testing::internal::GetCapturedStdout())); +} +TEST(memory_terp, list_push_back_var){ + // - + // - v1 + // - v2 + + sstd::terp::var tmp; + sstd::terp::var a; + tmp = sstd::terp::list(); + tmp.push_back("v1"); + tmp.push_back("v2"); + a = sstd::terp::list(); + a.push_back(tmp); // TEST THIS LINE + + ASSERT_STREQ(a[0][0].to().c_str(), "v1"); + ASSERT_STREQ(a[0][1].to().c_str(), "v2"); +} +TEST(memory_terp, list_push_back_var_move){ + // - + // - v1 + // - v2 + + sstd::terp::var tmp; + sstd::terp::var a; + tmp = sstd::terp::list(); + tmp.push_back("v1"); + tmp.push_back("v2"); + a = sstd::terp::list(); + a.push_back(std::move(tmp)); // TEST THIS LINE + + ASSERT_STREQ(a[0][0].to().c_str(), "v1"); + ASSERT_STREQ(a[0][1].to().c_str(), "v2"); +} // resize() TEST(memory_terp, list_resize){ @@ -252,19 +319,19 @@ TEST(memory_terp, list_size_arg_10){ TEST(memory_terp, list_typeNum){ sstd::terp::var a; a = sstd::terp::list(); - ASSERT_STREQ(sstd::typeNum2str(a.typeNum()).c_str(), "vec_void_ptr"); // TEST THIS LINE + ASSERT_STREQ(sstd::typeNum2str(a.typeNum()).c_str(), "vec_terp_var"); // TEST THIS LINE } // typeStr() TEST(memory_terp, list_typeStr){ sstd::terp::var a; a = sstd::terp::list(); - ASSERT_STREQ(a.typeStr().c_str(), "vec_void_ptr"); // TEST THIS LINE + ASSERT_STREQ(a.typeStr().c_str(), "vec_terp_var"); // TEST THIS LINE } -//*/ + //----------------------------------------------------------------------------------------------------------------------------------------------- // sstd::terp::hash -//* + // operator= TEST(memory_terp, hash_ope_assign){ sstd::terp::var a; @@ -438,16 +505,16 @@ TEST(memory_terp, hash_size_arg_14){ TEST(memory_terp, hash_typeNum){ sstd::terp::var a; a = sstd::terp::hash(); - ASSERT_STREQ(sstd::typeNum2str(a.typeNum()).c_str(), "hash_str_void_ptr"); // TEST THIS LINE + ASSERT_STREQ(sstd::typeNum2str(a.typeNum()).c_str(), "hash_terp_var"); // TEST THIS LINE } // typeStr() TEST(memory_terp, hash_typeStr){ sstd::terp::var a; a = sstd::terp::hash(); - ASSERT_STREQ(a.typeStr().c_str(), "hash_str_void_ptr"); // TEST THIS LINE + ASSERT_STREQ(a.typeStr().c_str(), "hash_terp_var"); // TEST THIS LINE } -//*/ + //----------------------------------------------------------------------------------------------------------------------------------------------- // complex test cases @@ -592,10 +659,10 @@ TEST(memory_terp, var_ope_eq_false_different_type){ //----------------------------------------------------------------------------------------------------------------------------------------------- // Type Conversion -#define TEST_VAR_CONSTRUCTOR_AND_TO(T, in) \ - T ans = in; \ +#define TEST_VAR_CONSTRUCTOR_AND_TO(T, in) \ + T ans = in; \ sstd::terp::var v = ans; \ - T ret = v.to(); /* TEST THIS LINE */ \ + T ret = v.to(); /* TEST THIS LINE */ \ ASSERT_TRUE(ret==ans); TEST(memory_terp, var_constructor_and_to_bool_true){ TEST_VAR_CONSTRUCTOR_AND_TO(bool, true); } diff --git a/test/src_test/string/strEdit.cpp b/test/src_test/string/strEdit.cpp index a779aca6..aad6665e 100644 --- a/test/src_test/string/strEdit.cpp +++ b/test/src_test/string/strEdit.cpp @@ -44,8 +44,8 @@ CD" )"; std::vector ans_vs = {"AB\nCD", "ghi"}; bool ret_tf = sstd::extract_quoted(ret_vs, s); // TEST THIS LINE - sstd::printn(ret_tf); - sstd::printn(ret_vs); + //sstd::printn(ret_tf); + //sstd::printn(ret_vs); ASSERT_TRUE( ret_tf ); ASSERT_TRUE( ret_vs == ans_vs ); @@ -63,8 +63,8 @@ CD\" )"; std::vector ans_vs; bool ret_tf = sstd::extract_quoted(ret_vs, s); // TEST THIS LINE - sstd::printn(ret_tf); - sstd::printn(ret_vs); + //sstd::printn(ret_tf); + //sstd::printn(ret_vs); ASSERT_TRUE( ret_tf ); ASSERT_TRUE( ret_vs == ans_vs ); @@ -74,8 +74,8 @@ TEST(strEdit, extract_quoted__false_unclosed_double_quate){ std::string s = R"( "ABCD )"; std::vector ans_vs; bool ret_tf = sstd::extract_quoted(ret_vs, s); // TEST THIS LINE - sstd::printn(ret_tf); - sstd::printn(ret_vs); + //sstd::printn(ret_tf); + //sstd::printn(ret_vs); ASSERT_FALSE( ret_tf ); } @@ -84,8 +84,8 @@ TEST(strEdit, extract_quoted__false_unclosed_single_quate){ std::string s = R"( 'ABCD )"; std::vector ans_vs; bool ret_tf = sstd::extract_quoted(ret_vs, s); // TEST THIS LINE - sstd::printn(ret_tf); - sstd::printn(ret_vs); + //sstd::printn(ret_tf); + //sstd::printn(ret_vs); ASSERT_FALSE( ret_tf ); } @@ -187,185 +187,149 @@ R"()"}) ); //----------------------------------------------------------------------------------------------------------------------------------------------- -TEST(strEdit, split_c){ - std::vector v = sstd::split(" a b, c"); // TEST THIS LINE - ASSERT_TRUE( v == std::vector({"a", "b,", "c"}) ); -} -TEST(strEdit, split_c_c_space){ - std::vector v = sstd::split(" a b, c", ' '); // TEST THIS LINE - ASSERT_TRUE( v == std::vector({"", "a", "", "b,", "c"}) ); -} -TEST(strEdit, split_c_c_comma){ - std::vector v = sstd::split(" a b, c", ','); // TEST THIS LINE - ASSERT_TRUE( v == std::vector({" a b", " c"}) ); -} +#define TEST_SPLIT_CS(S_IN, ...) \ + std::vector ret_v = sstd::split(S_IN); /* TEST THIS LINE */ \ + /* sstd::printn(ret_v); */ \ + ASSERT_TRUE(ret_v == std::vector({__VA_ARGS__}) ); -//--- +TEST(strEdit, split_c_0){ TEST_SPLIT_CS(" a b, c", "a", "b,", "c"); } +TEST(strEdit, split_c_1){ TEST_SPLIT_CS(" a b, c ", "a", "b,", "c"); } +TEST(strEdit, split_c_2){ TEST_SPLIT_CS(" a b, c ", "a", "b,", "c"); } +TEST(strEdit, split_s){ TEST_SPLIT_CS(std::string(" a b, c"), "a", "b,", "c"); } -TEST(strEdit, split_s){ - std::vector v = sstd::split(std::string(" a b, c")); // TEST THIS LINE - ASSERT_TRUE( v == std::vector({"a", "b,", "c"}) ); -} -TEST(strEdit, split_s_c){ - std::vector v = sstd::split(std::string(" a b, c"), ' '); // TEST THIS LINE - ASSERT_TRUE( v == std::vector({"", "a", "", "b,", "c"}) ); -} +#undef TEST_SPLIT_CS //--- -TEST(strEdit, split_rmSpace_c){ - std::vector v = sstd::split_rmSpace(" a b, c"); // TEST THIS LINE - ASSERT_TRUE( v == std::vector({"a", "b,", "c"}) ); -} -TEST(strEdit, split_rmSpace_c_c_space){ - std::vector v = sstd::split_rmSpace(" a b, c", ' '); // TEST THIS LINE - ASSERT_TRUE( v == std::vector({"a", "b,", "c"}) ); -} -TEST(strEdit, split_rmSpace_c_c_comma){ - std::vector v = sstd::split_rmSpace(" a b, c", ','); // TEST THIS LINE - ASSERT_TRUE( v == std::vector({"a b", "c"}) ); -} +#define TEST_SPLIT_CS_X(X_IN, S_IN, ...) \ + std::vector ret_v = sstd::split(S_IN, X_IN); /* TEST THIS LINE */ \ + /* sstd::printn(ret_v); */ \ + ASSERT_TRUE(ret_v == std::vector({__VA_ARGS__}) ); + +TEST(strEdit, split_c_c_space_0){ TEST_SPLIT_CS_X(' ', "a b, c", "a", "", "b,", "c"); } +TEST(strEdit, split_c_c_space_1){ TEST_SPLIT_CS_X(' ', " a b, c ", "", "a", "", "b,", "c", ""); } +TEST(strEdit, split_c_c_space_2){ TEST_SPLIT_CS_X(' ', " a b, c ", "", "", "a", "", "b,", "c", "", ""); } +TEST(strEdit, split_c_c_comma){ TEST_SPLIT_CS_X(',', " a b, c", " a b", " c"); } + +TEST(strEdit, split_s_c){ TEST_SPLIT_CS_X(' ', std::string(" a b, c"), "", "a", "", "b,", "c"); } + +#undef TEST_SPLIT_CS_X //--- -TEST(strEdit, split_rmSpace_s){ - std::vector v = sstd::split_rmSpace(std::string(" a b, c")); // TEST THIS LINE - ASSERT_TRUE( v == std::vector({"a", "b,", "c"}) ); -} -TEST(strEdit, split_rmSpace_s_c_space){ - std::vector v = sstd::split_rmSpace(std::string(" a b, c"), ' '); // TEST THIS LINE - ASSERT_TRUE( v == std::vector({"a", "b,", "c"}) ); -} +#define TEST_SPLIT_SS_X(X_IN, S_IN, ...) \ + std::vector ret_v = sstd::split(S_IN, X_IN); /* TEST THIS LINE */ \ + /* sstd::printn(ret_v); */ \ + ASSERT_TRUE(ret_v == std::vector({__VA_ARGS__}) ); -//----------------------------------------------------------------------------------------------------------------------------------------------- +TEST(strEdit, split_s_s_space_1_0){ TEST_SPLIT_SS_X(",", "a,b,c", "a", "b", "c"); } -TEST(strEdit, split_quotes_s_c__case_true_0){ - std::string s = ""; - const char X = ':'; +TEST(strEdit, split_s_s_space_m_0){ TEST_SPLIT_SS_X("xxx", "123abcabs456", "123abcabs456"); } +TEST(strEdit, split_s_s_space_m_1){ TEST_SPLIT_SS_X("abc", "123abcabs456", "123", "abs456"); } +TEST(strEdit, split_s_s_space_m_2a){ TEST_SPLIT_SS_X("abc", "123abc456abc789", "123", "456", "789"); } +TEST(strEdit, split_s_s_space_m_2b){ TEST_SPLIT_SS_X("abc", "123abc456abc789abc", "123", "456", "789", ""); } - bool ret_tf; - std::vector ret_v; - ret_tf = sstd::split_quotes(ret_v, s, X); // TEST THIS LINE -// sstd::printn(ret_v); - - ASSERT_TRUE(ret_tf); - ASSERT_TRUE(ret_v.size() == (uint)0 ); -} -TEST(strEdit, split_quotes_s_c__case_true_1){ - std::string s = " abc "; - const char X = ':'; +TEST(strEdit, split_s_s){ TEST_SPLIT_SS_X(std::string("abc"), std::string("123abc456abc789"), std::string("123"), std::string("456"), std::string("789")); } - bool ret_tf; - std::vector ret_v; - ret_tf = sstd::split_quotes(ret_v, s, X); // TEST THIS LINE -// sstd::printn(ret_v); - - ASSERT_TRUE(ret_tf); - ASSERT_TRUE(ret_v == std::vector({" abc "}) ); -} -TEST(strEdit, split_quotes_s_c__case_true_2){ - std::string s = " abc : def "; - const char X = ':'; +#undef TEST_SPLIT_SS_X - bool ret_tf; - std::vector ret_v; - ret_tf = sstd::split_quotes(ret_v, s, X); // TEST THIS LINE -// sstd::printn(ret_v); - - ASSERT_TRUE(ret_tf); - ASSERT_TRUE(ret_v == std::vector({" abc ", " def "}) ); -} -TEST(strEdit, split_quotes_s_c__case_true_3){ - std::string s = " abc : def : ghi "; - const char X = ':'; +//--- - bool ret_tf; - std::vector ret_v; - ret_tf = sstd::split_quotes(ret_v, s, X); // TEST THIS LINE -// sstd::printn(ret_v); - - ASSERT_TRUE(ret_tf); - ASSERT_TRUE(ret_v == std::vector({" abc ", " def ", " ghi "}) ); -} +#define TEST_SPLIT_RMSPACE_CS(S_IN, ...) \ + std::vector ret_v = sstd::split_rmSpace(S_IN); /* TEST THIS LINE */ \ + /* sstd::printn(ret_v); */ \ + ASSERT_TRUE(ret_v == std::vector({__VA_ARGS__}) ); + +TEST(strEdit, split_rmSpace_c){ TEST_SPLIT_RMSPACE_CS(" a b, c", "a", "b,", "c"); } +TEST(strEdit, split_rmSpace_s){ TEST_SPLIT_RMSPACE_CS(std::string(" a b, c"), "a", "b,", "c"); } + +#undef TEST_SPLIT_RMSPACE_CS //--- -TEST(strEdit, split_quotes_s_c__case_true_sq){ - std::string s = "' a:b:c ':' d:ef ':' gh:i '"; - const char X = ':'; +#define TEST_SPLIT_RMSPACE_CS_X(X_IN, S_IN, ...) \ + std::vector ret_v = sstd::split_rmSpace(S_IN, X_IN); /* TEST THIS LINE */ \ + /* sstd::printn(ret_v); */ \ + ASSERT_TRUE(ret_v == std::vector({__VA_ARGS__}) ); - bool ret_tf; - std::vector ret_v; - ret_tf = sstd::split_quotes(ret_v, s, X); // TEST THIS LINE -// sstd::printn(ret_v); - - ASSERT_TRUE(ret_tf); - ASSERT_TRUE(ret_v == std::vector({"' a:b:c '", "' d:ef '", "' gh:i '"}) ); -} +TEST(strEdit, split_rmSpace_c_c_space){ TEST_SPLIT_RMSPACE_CS_X(' ', " a b, c", "a", "b,", "c"); } +TEST(strEdit, split_rmSpace_c_c_comma){ TEST_SPLIT_RMSPACE_CS_X(',', " a b, c", "a b", "c"); } +TEST(strEdit, split_rmSpace_s_c_space){ TEST_SPLIT_RMSPACE_CS_X(' ', std::string(" a b, c"), "a", "b,", "c"); } -TEST(strEdit, split_quotes_s_c__case_true_dq){ - std::string s = R"(" a:b:c ":" d:ef ":" gh:i ")"; - const char X = ':'; +#undef TEST_SPLIT_RMSPACE_CS_X - bool ret_tf; - std::vector ret_v; - ret_tf = sstd::split_quotes(ret_v, s, X); // TEST THIS LINE -// sstd::printn(ret_v); - - ASSERT_TRUE(ret_tf); - ASSERT_TRUE(ret_v == std::vector({R"(" a:b:c ")", R"(" d:ef ")", R"(" gh:i ")"}) ); -} +//----------------------------------------------------------------------------------------------------------------------------------------------- + +#define TEST_SPLIT_QUOTES_VS_CS(RESULT, S_IN, ...) \ + bool ret_tf; \ + std::vector ret_v; \ + ret_tf = sstd::split_quotes(ret_v, S_IN); /* TEST THIS LINE */ \ + /* sstd::printn(ret_v); */ \ + \ + ASSERT_TRUE(ret_tf == RESULT); \ + ASSERT_TRUE(ret_v == std::vector({__VA_ARGS__}) ); + +TEST(strEdit, split_quotes_vs_s){ TEST_SPLIT_QUOTES_VS_CS(true, std::string("a b c d"), "a", "b", "c", "d"); } + +TEST(strEdit, split_quotes_vs_c__case_true_space_0){ TEST_SPLIT_QUOTES_VS_CS(true, "a b c d", "a", "b", "c", "d"); } +TEST(strEdit, split_quotes_vs_c__case_true_space_1){ TEST_SPLIT_QUOTES_VS_CS(true, " a b c d ", "a", "b", "c", "d"); } +TEST(strEdit, split_quotes_vs_c__case_true_space_2){ TEST_SPLIT_QUOTES_VS_CS(true, " a b c d ", "a", "b", "c", "d"); } + +#undef TEST_SPLIT_QUOTES_VS_CS //--- -TEST(strEdit, split_quotes_s_c__case_false_sq_01){ - std::string s = R"(' a:b:c : d:ef )"; - const char X = ':'; +#define TEST_SPLIT_QUOTES_VS_CS_X(RESULT, X_IN, S_IN, ...) \ + bool ret_tf; \ + std::vector ret_v; \ + ret_tf = sstd::split_quotes(ret_v, S_IN, X_IN); /* TEST THIS LINE */ \ + /* sstd::printn(ret_v); */ \ + \ + ASSERT_TRUE(ret_tf == RESULT); \ + ASSERT_TRUE(ret_v == std::vector({__VA_ARGS__}) ); - bool ret_tf; - std::vector ret_v; - ret_tf = sstd::split_quotes(ret_v, s, X); // TEST THIS LINE -// sstd::printn(ret_v); - - ASSERT_TRUE(!ret_tf); - ASSERT_TRUE(ret_v.size() == (uint)0 ); -} -TEST(strEdit, split_quotes_s_c__case_false_sq_02){ - std::string s = R"( a:b:c : d:ef ')"; - const char X = ':'; +TEST(strEdit, split_quotes_vs_c_s){ TEST_SPLIT_QUOTES_VS_CS_X(true, ' ', std::string("a b c d"), "a", "", "b", "", "c", "d"); } - bool ret_tf; - std::vector ret_v; - ret_tf = sstd::split_quotes(ret_v, s, X); // TEST THIS LINE -// sstd::printn(ret_v); - - ASSERT_TRUE(!ret_tf); - ASSERT_TRUE(ret_v.size() == (uint)0 ); -} -TEST(strEdit, split_quotes_s_c__case_false_dq_01){ - std::string s = R"(" a:b:c : d:ef )"; - const char X = ':'; +//TEST(strEdit, split_quotes_vs_c_x__case_true_null){ TEST_SPLIT_QUOTES_VS_CS_X(true, ' ', "", ""); } // for compatible with Python split() - bool ret_tf; - std::vector ret_v; - ret_tf = sstd::split_quotes(ret_v, s, X); // TEST THIS LINE -// sstd::printn(ret_v); - - ASSERT_TRUE(!ret_tf); - ASSERT_TRUE(ret_v.size() == (uint)0 ); -} -TEST(strEdit, split_quotes_s_c__case_false_dq_02){ - std::string s = R"( a:b:c : d:ef ")"; - const char X = ':'; +TEST(strEdit, split_quotes_vs_c_x__case_true_space_0){ TEST_SPLIT_QUOTES_VS_CS_X(true, ' ', "a b c d", "a", "", "b", "", "c", "d"); } +TEST(strEdit, split_quotes_vs_c_x__case_true_space_1){ TEST_SPLIT_QUOTES_VS_CS_X(true, ' ', " a b c d ", "", "a", "", "b", "", "c", "d", ""); } +TEST(strEdit, split_quotes_vs_c_x__case_true_space_2){ TEST_SPLIT_QUOTES_VS_CS_X(true, ' ', " a b c d ", "", "", "a", "", "b", "", "c", "d", "", ""); } - bool ret_tf; - std::vector ret_v; - ret_tf = sstd::split_quotes(ret_v, s, X); // TEST THIS LINE -// sstd::printn(ret_v); - - ASSERT_TRUE(!ret_tf); - ASSERT_TRUE(ret_v.size() == (uint)0 ); -} +//TEST(strEdit, split_quotes_vs_c_x__case_true_0){ TEST_SPLIT_QUOTES_VS_CS_X(true, ':', "", ""); } // for compatible with Python split() +TEST(strEdit, split_quotes_vs_c_x__case_true_1){ TEST_SPLIT_QUOTES_VS_CS_X(true, ':', " abc ", " abc "); } +TEST(strEdit, split_quotes_vs_c_x__case_true_2){ TEST_SPLIT_QUOTES_VS_CS_X(true, ':', " abc : def ", " abc ", " def "); } +TEST(strEdit, split_quotes_vs_c_x__case_true_3){ TEST_SPLIT_QUOTES_VS_CS_X(true, ':', " abc : def : ghi ", " abc ", " def ", " ghi "); } + +TEST(strEdit, split_quotes_vs_c_x__case_true_sq){ TEST_SPLIT_QUOTES_VS_CS_X(true, ':', "' a:b:c ':' d:ef ':' gh:i '", "' a:b:c '", "' d:ef '", "' gh:i '"); } +TEST(strEdit, split_quotes_vs_c_x__case_true_dq){ TEST_SPLIT_QUOTES_VS_CS_X(true, ':', R"(" a:b:c ":" d:ef ":" gh:i ")", R"(" a:b:c ")", R"(" d:ef ")", R"(" gh:i ")"); } + +TEST(strEdit, split_quotes_vs_c_x__case_false_sq_01){ TEST_SPLIT_QUOTES_VS_CS_X(false, ':', R"(' a:b:c : d:ef )"); } +TEST(strEdit, split_quotes_vs_c_x__case_false_sq_02){ TEST_SPLIT_QUOTES_VS_CS_X(false, ':', R"( a:b:c : d:ef ')"); } +TEST(strEdit, split_quotes_vs_c_x__case_false_dq_01){ TEST_SPLIT_QUOTES_VS_CS_X(false, ':', R"(" a:b:c : d:ef )"); } +TEST(strEdit, split_quotes_vs_c_x__case_false_dq_02){ TEST_SPLIT_QUOTES_VS_CS_X(false, ':', R"( a:b:c : d:ef ")"); } + +#undef TEST_SPLIT_QUOTES_VS_CS_X + +//--- + +#define TEST_SPLIT_QUOTES_VS_CS_XCS(RESULT, X_IN, S_IN, ...) \ + bool ret_tf; \ + std::vector ret_v; \ + ret_tf = sstd::split_quotes(ret_v, S_IN, X_IN); /* TEST THIS LINE */ \ + /* sstd::printn(ret_v); */ \ + \ + ASSERT_TRUE(ret_tf == RESULT); \ + ASSERT_TRUE(ret_v == std::vector({__VA_ARGS__}) ); + +TEST(strEdit, split_quotes_vs_c_s_xc){ std::vector ret_v; sstd::split_quotes(ret_v, "", ""); } +TEST(strEdit, split_quotes_vs_c_s_xs){ std::vector ret_v; sstd::split_quotes(ret_v, "", ""); } +TEST(strEdit, split_quotes_vs_c_s_xcs_00){ TEST_SPLIT_QUOTES_VS_CS_XCS(true, " ", "a b c d", "a", "", "b", "", "c", "d"); } +TEST(strEdit, split_quotes_vs_c_s_xcs_01){ TEST_SPLIT_QUOTES_VS_CS_XCS(true, ": ", "k:1:2: v:1:2:", "k:1:2", "v:1:2:"); } +TEST(strEdit, split_quotes_vs_c_s_xcs_02){ TEST_SPLIT_QUOTES_VS_CS_XCS(true, ": ", ": k:1:2: v:1:2: ", "", "k:1:2", "v:1:2", ""); } +TEST(strEdit, split_quotes_vs_c_s_xcs_03){ TEST_SPLIT_QUOTES_VS_CS_XCS(true, ": ", ": : k:1:2: v:1:2: : ", "", "", "k:1:2", "v:1:2", "", ""); } + +#undef TEST_SPLIT_QUOTES_VS_CS_XCS //----------------------------------------------------------------------------------------------------------------------------------------------- @@ -629,6 +593,87 @@ TEST(strEdit, stripAll_ss){ strEdit_stripAll_check_io(str_in, std::strin #undef strEdit_stripAll_check_io //----------------------------------------------------------------------------------------------------------------------------------------------- +// rstripAll_ow(), lstripAll_ow(), stripAll_ow() + +TEST(strEdit, lstripAll_ow_sc_case01_01a){ + std::string str_in = "0a0b0cx0d0xe0f0g0"; + std::string str_ans = "a0b0cx0d0xe0f0g0"; + sstd::lstripAll_ow(str_in, "x0"); + ASSERT_STREQ(str_in.c_str(), str_ans.c_str()); +} +TEST(strEdit, lstripAll_ow_sc__case01_01b){ + std::string str_in = "0a0b0cx0d0xe0f0g0"; + std::string str_ans = ""; + sstd::lstripAll_ow(str_in, "0a0b0cx0d0xe0f0g0"); + ASSERT_STREQ(str_in.c_str(), str_ans.c_str()); +} +TEST(strEdit, lstripAll_ow_sc_case01_02){ + std::string str_in = ""; + std::string str_ans = ""; + sstd::lstripAll_ow(str_in, "x0"); + ASSERT_STREQ(str_in.c_str(), str_ans.c_str()); +} +TEST(strEdit, lstripAll_ow_sc_case01_03){ + std::string str_in = ""; + std::string str_ans = ""; + sstd::lstripAll_ow(str_in, ""); + ASSERT_STREQ(str_in.c_str(), str_ans.c_str()); +} +TEST(strEdit, lstripAll_ow_sc_case02){ + std::string str_in = "0000000000000000000000000000xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0000000x0x0x0x0x0x000x0x0xxx0000x0x0xx00000x00x0x0x00000000000000000000000000000xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0000000x0x0x0x0x0x000x0x0xxx0000x0x0xx00000x00x0x0x00000000000000000000000000000xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0000000x0x0x0x0x0x000x0x0xxx0000x0x0xx00000x00x0x0x0a0b0cx0d0xe0f0g0x"; + std::string str_ans = "a0b0cx0d0xe0f0g0x"; + sstd::lstripAll_ow(str_in, "x0"); + ASSERT_STREQ(str_in.c_str(), str_ans.c_str()); +} + +TEST(strEdit, lstripAll_ow_ss_case01_01){ + std::string str_in = "0a0b0cx0d0xe0f0g0"; + std::string str_ans = "a0b0cx0d0xe0f0g0"; + sstd::lstripAll_ow(str_in, std::string("x0")); + ASSERT_STREQ(str_in.c_str(), str_ans.c_str()); +} + +//--- + +TEST(strEdit, rstripAll_ow_sc_case01_01a){ + std::string str_in = "0a0b0cx0d0xe0f0g0"; + std::string str_ans = "0a0b0cx0d0xe0f0g"; + sstd::rstripAll_ow(str_in, "x0"); + ASSERT_STREQ(str_in.c_str(), str_ans.c_str()); +} +TEST(strEdit, rstripAll_ow_sc__case01_01b){ + std::string str_in = "0a0b0cx0d0xe0f0g0"; + std::string str_ans = ""; + sstd::rstripAll_ow(str_in, "abcdefgx0"); + ASSERT_STREQ(str_in.c_str(), str_ans.c_str()); +} +TEST(strEdit, rstripAll_ow_sc_case01_02){ + std::string str_in = ""; + std::string str_ans = ""; + sstd::rstripAll_ow(str_in, "x0"); + ASSERT_STREQ(str_in.c_str(), str_ans.c_str()); +} +TEST(strEdit, rstripAll_ow_sc_case01_03){ + std::string str_in = ""; + std::string str_ans = ""; + sstd::rstripAll_ow(str_in, ""); + ASSERT_STREQ(str_in.c_str(), str_ans.c_str()); +} +TEST(strEdit, rstripAll_ow_sc_case02){ + std::string str_in = "0a0b0cx0d0xe0f0g00000000000000000000000000000xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0000000x0x0x0x0x0x000x0x0xxx0000x0x0xx00000x00x0x0x00000000000000000000000000000xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0000000x0x0x0x0x0x000x0x0xxx0000x0x0xx00000x00x0x0x00000000000000000000000000000xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0000000x0x0x0x0x0x000x0x0xxx0000x0x0xx00000x00x0x0x"; + std::string str_ans = "0a0b0cx0d0xe0f0g"; + sstd::rstripAll_ow(str_in, "x0"); + ASSERT_STREQ(str_in.c_str(), str_ans.c_str()); +} + +TEST(strEdit, rstripAll_ow_ss_case01_01){ + std::string str_in = "0a0b0cx0d0xe0f0g0"; + std::string str_ans = "0a0b0cx0d0xe0f0g"; + sstd::rstripAll_ow(str_in, std::string("x0")); + ASSERT_STREQ(str_in.c_str(), str_ans.c_str()); +} + +//--- TEST(strEdit, stripAll_ow_case01_01){ std::string str_in = "0a0b0cx0d0xe0f0g0"; diff --git a/test/src_test/string/strmatch.cpp b/test/src_test/string/strmatch.cpp index dca73387..c84d6ef0 100644 --- a/test/src_test/string/strmatch.cpp +++ b/test/src_test/string/strmatch.cpp @@ -1,6 +1,28 @@ #include #include "../../gtest_parallel/test_main.hpp" +//----------------------------------------------------------------------------------------------------------------------------------------------- +// startswith() + +TEST(strmatch, startswith_c_c){ sstd::startswith( "" , "" ); } +TEST(strmatch, startswith_c_s){ sstd::startswith( "" , std::string("")); } +TEST(strmatch, startswith_s_c){ sstd::startswith(std::string(""), "" ); } +TEST(strmatch, startswith_s_s){ sstd::startswith(std::string(""), std::string("")); } + +TEST(strmatch, startswith_null){ ASSERT_TRUE(sstd::startswith("", "")); } +TEST(strmatch, startswith_01){ ASSERT_TRUE(sstd::startswith("abc", "")); } +TEST(strmatch, startswith_02){ ASSERT_TRUE(!sstd::startswith("abc", "b")); } +TEST(strmatch, startswith_03){ ASSERT_TRUE(sstd::startswith("abc", "abc")); } +TEST(strmatch, startswith_04){ ASSERT_TRUE(sstd::startswith("abcdef", "abc")); } + +//----------------------------------------------------------------------------------------------------------------------------------------------- +// strcmp() + +TEST(strmatch, strcmp_c_c){ sstd::strcmp( "" , "" ); } +TEST(strmatch, strcmp_c_s){ sstd::strcmp( "" , std::string("")); } +TEST(strmatch, strcmp_s_c){ sstd::strcmp(std::string(""), "" ); } +TEST(strmatch, strcmp_s_s){ sstd::strcmp(std::string(""), std::string("")); } + //----------------------------------------------------------------------------------------------------------------------------------------------- // strmatch() and strmatch_getWC() @@ -63,6 +85,46 @@ TEST(strmatch, pathmatch){ ASSERT_TRUE ( sstd::pathmatch(str, wildcard4) ); ASSERT_TRUE ( sstd::pathmatch(str, wildcard5) ); } + +//----------------------------------------------------------------------------------------------------------------------------------------------- +// rcount(), lcount(), count() + +TEST(strmatch, rcount_cc){ + ASSERT_EQ(sstd::rcount("abcdef", 'x'), (uint)0); + ASSERT_EQ(sstd::rcount("abcdef", 'f'), (uint)1); + ASSERT_EQ(sstd::rcount("abcfff", 'f'), (uint)3); + ASSERT_EQ(sstd::rcount("", 'a'), (uint)0); +} +TEST(strmatch, rcount_sc){ + ASSERT_EQ(sstd::rcount(std::string("abcdef"), 'x'), (uint)0); +} + +//--- + +TEST(strmatch, lcount_cc){ + ASSERT_EQ(sstd::lcount("abcdef", 'x'), (uint)0); + ASSERT_EQ(sstd::lcount("abcdef", 'a'), (uint)1); + ASSERT_EQ(sstd::lcount("aaabcd", 'a'), (uint)3); + ASSERT_EQ(sstd::lcount("", 'a'), (uint)0); +} +TEST(strmatch, lcount_sc){ + ASSERT_EQ(sstd::lcount(std::string("abcdef"), 'x'), (uint)0); +} + +//--- + +TEST(strmatch, count_cc){ + ASSERT_EQ(sstd::count("abcdef", 'x'), (uint)0); + ASSERT_EQ(sstd::count("abcdef", 'a'), (uint)1); + ASSERT_EQ(sstd::count("xbxdex", 'x'), (uint)3); + ASSERT_EQ(sstd::count("", 'a'), (uint)0); +} +TEST(strmatch, count_sc){ + ASSERT_EQ(sstd::count(std::string("abcdef"), 'x'), (uint)0); +} + +//----------------------------------------------------------------------------------------------------------------------------------------------- + TEST(strmatch, isNum_char){ ASSERT_TRUE ( sstd::isNum('0') ); ASSERT_TRUE ( sstd::isNum('5') ); @@ -306,6 +368,9 @@ TEST(strmatch, strIn){ bool ret=sstd::strIn(lhs, rhs); ASSERT_FALSE(ret); } } +TEST(strmatch, strIn_02){ + ASSERT_TRUE(sstd::strIn(": ", "k:1:: v:1")); +} //-----------------------------------------------------------------------------------------------------------------------------------------------