diff options
Diffstat (limited to 'tests/test.lua')
-rwxr-xr-x | tests/test.lua | 157 |
1 files changed, 91 insertions, 66 deletions
diff --git a/tests/test.lua b/tests/test.lua index 582f55e..8fafdf3 100755 --- a/tests/test.lua +++ b/tests/test.lua | |||
@@ -657,133 +657,158 @@ ___'' | |||
657 | print("testing C API ...") | 657 | print("testing C API ...") |
658 | local mod = require("testmod") | 658 | local mod = require("testmod") |
659 | ___'' | 659 | ___'' |
660 | print(mod.isinteger(1)) | 660 | print("isinteger", mod.isinteger(1)) |
661 | print(mod.isinteger(0)) | 661 | print("isinteger", mod.isinteger(0)) |
662 | print(mod.isinteger(1234567)) | 662 | print("isinteger", mod.isinteger(1234567)) |
663 | print(mod.isinteger(12.3)) | 663 | print("isinteger", mod.isinteger(12.3)) |
664 | print(mod.isinteger(math.huge)) | 664 | print("isinteger", mod.isinteger(math.huge)) |
665 | print(mod.isinteger(math.sqrt(-1))) | 665 | print("isinteger", mod.isinteger(math.sqrt(-1))) |
666 | 666 | ||
667 | 667 | ||
668 | ___'' | 668 | ___'' |
669 | print(mod.rotate(1, 1, 2, 3, 4, 5, 6)) | 669 | print("rotate", mod.rotate(1, 1, 2, 3, 4, 5, 6)) |
670 | print(mod.rotate(-1, 1, 2, 3, 4, 5, 6)) | 670 | print("rotate", mod.rotate(-1, 1, 2, 3, 4, 5, 6)) |
671 | print(mod.rotate(4, 1, 2, 3, 4, 5, 6)) | 671 | print("rotate", mod.rotate(4, 1, 2, 3, 4, 5, 6)) |
672 | print(mod.rotate(-4, 1, 2, 3, 4, 5, 6)) | 672 | print("rotate", mod.rotate(-4, 1, 2, 3, 4, 5, 6)) |
673 | 673 | ||
674 | 674 | ||
675 | ___'' | 675 | ___'' |
676 | print(mod.strtonum("+123")) | 676 | print("strtonum", mod.strtonum("+123")) |
677 | print(mod.strtonum(" 123 ")) | 677 | print("strtonum", mod.strtonum(" 123 ")) |
678 | print(mod.strtonum("-1.23")) | 678 | print("strtonum", mod.strtonum("-1.23")) |
679 | print(mod.strtonum(" 123 abc")) | 679 | print("strtonum", mod.strtonum(" 123 abc")) |
680 | print(mod.strtonum("jkl")) | 680 | print("strtonum", mod.strtonum("jkl")) |
681 | 681 | ||
682 | 682 | ||
683 | ___'' | 683 | ___'' |
684 | local a, b, c = mod.requiref() | 684 | local a, b, c = mod.requiref() |
685 | print( type(a), type(b), type(c), | 685 | print("requiref", type(a), type(b), type(c), |
686 | a.boolean, b.boolean, c.boolean, | 686 | a.boolean, b.boolean, c.boolean, |
687 | type(requiref1), type(requiref2), type(requiref3)) | 687 | type(requiref1), type(requiref2), type(requiref3)) |
688 | 688 | ||
689 | ___'' | 689 | ___'' |
690 | local proxy, backend = {}, {} | 690 | local proxy, backend = {}, {} |
691 | setmetatable(proxy, { __index = backend, __newindex = backend }) | 691 | setmetatable(proxy, { __index = backend, __newindex = backend }) |
692 | print(rawget(proxy, 1), rawget(backend, 1)) | 692 | print("geti/seti", rawget(proxy, 1), rawget(backend, 1)) |
693 | print(mod.getseti(proxy, 1)) | 693 | print("geti/seti", mod.getseti(proxy, 1)) |
694 | print(rawget(proxy, 1), rawget(backend, 1)) | 694 | print("geti/seti", rawget(proxy, 1), rawget(backend, 1)) |
695 | print(mod.getseti(proxy, 1)) | 695 | print("geti/seti", mod.getseti(proxy, 1)) |
696 | print(rawget(proxy, 1), rawget(backend, 1)) | 696 | print("geti/seti", rawget(proxy, 1), rawget(backend, 1)) |
697 | 697 | ||
698 | -- tests for Lua 5.1 | 698 | -- tests for Lua 5.1 |
699 | ___'' | 699 | ___'' |
700 | print(mod.tonumber(12)) | 700 | print("tonumber", mod.tonumber(12)) |
701 | print(mod.tonumber("12")) | 701 | print("tonumber", mod.tonumber("12")) |
702 | print(mod.tonumber("0")) | 702 | print("tonumber", mod.tonumber("0")) |
703 | print(mod.tonumber(false)) | 703 | print("tonumber", mod.tonumber(false)) |
704 | print(mod.tonumber("error")) | 704 | print("tonumber", mod.tonumber("error")) |
705 | 705 | ||
706 | ___'' | 706 | ___'' |
707 | print(mod.tointeger(12)) | 707 | print("tointeger", mod.tointeger(12)) |
708 | print(mod.tointeger("12")) | 708 | print("tointeger", mod.tointeger("12")) |
709 | print(mod.tointeger("0")) | 709 | print("tointeger", mod.tointeger("0")) |
710 | print( "aaa" ) | 710 | print("tointeger", mod.tointeger(math.pi)) |
711 | print(mod.tointeger(math.pi)) | 711 | print("tointeger", mod.tointeger(false)) |
712 | print( "bbb" ) | 712 | print("tointeger", mod.tointeger("error")) |
713 | print(mod.tointeger(false)) | ||
714 | print(mod.tointeger("error")) | ||
715 | 713 | ||
716 | ___'' | 714 | ___'' |
717 | print(mod.len("123")) | 715 | print("len", mod.len("123")) |
718 | print(mod.len({ 1, 2, 3})) | 716 | print("len", mod.len({ 1, 2, 3})) |
719 | print(pcall(mod.len, true)) | 717 | print("len", pcall(mod.len, true)) |
720 | local ud, meta = mod.newproxy() | 718 | local ud, meta = mod.newproxy() |
721 | meta.__len = function() return 5 end | 719 | meta.__len = function() return 5 end |
722 | print(mod.len(ud)) | 720 | print("len", mod.len(ud)) |
723 | meta.__len = function() return true end | 721 | meta.__len = function() return true end |
724 | print(pcall(mod.len, ud)) | 722 | print("len", pcall(mod.len, ud)) |
725 | 723 | ||
726 | ___'' | 724 | ___'' |
727 | print(mod.copy(true, "string", {}, 1)) | 725 | print("copy", mod.copy(true, "string", {}, 1)) |
728 | 726 | ||
729 | ___'' | 727 | ___'' |
730 | print(mod.rawxetp()) | 728 | print("rawgetp/rawsetp", mod.rawxetp()) |
731 | print(mod.rawxetp("I'm back")) | 729 | print("rawgetp/rawsetp", mod.rawxetp("I'm back")) |
732 | 730 | ||
733 | ___'' | 731 | ___'' |
734 | print(F(mod.globals()), mod.globals() == _G) | 732 | print("globals", F(mod.globals()), mod.globals() == _G) |
735 | 733 | ||
736 | ___'' | 734 | ___'' |
737 | local t = {} | 735 | local t = {} |
738 | print(F(mod.subtable(t))) | 736 | print("getsubtable", F(mod.subtable(t))) |
739 | local x, msg = mod.subtable(t) | 737 | local x, msg = mod.subtable(t) |
740 | print(F(x, msg, x == t.xxx)) | 738 | print("getsubtable", F(x, msg, x == t.xxx)) |
741 | 739 | ||
742 | ___'' | 740 | ___'' |
743 | print(F(mod.udata())) | 741 | print("udata", F(mod.udata())) |
744 | print(mod.udata("nosuchtype")) | 742 | print("udata", mod.udata("nosuchtype")) |
745 | 743 | ||
746 | ___'' | 744 | ___'' |
747 | print(F(mod.uservalue())) | 745 | print("uservalue", F(mod.uservalue())) |
748 | 746 | ||
749 | ___'' | 747 | ___'' |
750 | print(mod.getupvalues()) | 748 | print("upvalues", mod.getupvalues()) |
751 | 749 | ||
752 | ___'' | 750 | ___'' |
753 | print(mod.absindex("hi", true)) | 751 | print("absindex", mod.absindex("hi", true)) |
754 | 752 | ||
755 | ___'' | 753 | ___'' |
756 | print(mod.arith(2, 1)) | 754 | print("arith", mod.arith(2, 1)) |
757 | print(mod.arith(3, 5)) | 755 | print("arith", mod.arith(3, 5)) |
758 | 756 | ||
759 | ___'' | 757 | ___'' |
760 | print(mod.compare(1, 1)) | 758 | print("compare", mod.compare(1, 1)) |
761 | print(mod.compare(2, 1)) | 759 | print("compare", mod.compare(2, 1)) |
762 | print(mod.compare(1, 2)) | 760 | print("compare", mod.compare(1, 2)) |
763 | 761 | ||
764 | ___'' | 762 | ___'' |
765 | print(mod.tolstring("string")) | 763 | print("tolstring", mod.tolstring("string")) |
766 | local t = setmetatable({}, { | 764 | local t = setmetatable({}, { |
767 | __tostring = function(v) return "mytable" end | 765 | __tostring = function(v) return "mytable" end |
768 | }) | 766 | }) |
769 | print(mod.tolstring(t)) | 767 | print("tolstring", mod.tolstring(t)) |
770 | local t = setmetatable({}, { | 768 | local t = setmetatable({}, { |
771 | __tostring = function(v) return nil end | 769 | __tostring = function(v) return nil end |
772 | }) | 770 | }) |
773 | print(pcall(mod.tolstring, t)) | 771 | print("tolstring", pcall(mod.tolstring, t)) |
774 | local ud, meta = mod.newproxy() | 772 | local ud, meta = mod.newproxy() |
775 | meta.__name = "XXX" | 773 | meta.__name = "XXX" |
776 | print(mod.tolstring(ud):gsub(":.*$", ": yyy")) | 774 | print("tolstring", mod.tolstring(ud):gsub(":.*$", ": yyy")) |
777 | 775 | ||
778 | ___'' | 776 | ___'' |
779 | print(mod.pushstring()) | 777 | print("pushstring", mod.pushstring()) |
780 | 778 | ||
781 | ___'' | 779 | ___'' |
782 | print(mod.buffer()) | 780 | print("Buffer", mod.buffer()) |
783 | 781 | ||
784 | ___'' | 782 | ___'' |
785 | print(mod.exec("exit 0")) | 783 | print("execresult", mod.exec("exit 0")) |
786 | print(mod.exec("exit 1")) | 784 | print("execresult", mod.exec("exit 1")) |
787 | print(mod.exec("exit 25")) | 785 | print("execresult", mod.exec("exit 25")) |
786 | |||
787 | ___'' | ||
788 | do | ||
789 | local bin = string.dump(function() end) | ||
790 | local modes = { "t", "b", "bt" } | ||
791 | local codes = { | ||
792 | "", "return true", bin, "invalidsource", "\27invalidbinary" | ||
793 | } | ||
794 | for _,m in ipairs(modes) do | ||
795 | for i,c in ipairs(codes) do | ||
796 | print("loadbufferx", m, i, F(mod.loadstring(c, m))) | ||
797 | end | ||
798 | end | ||
799 | |||
800 | ___'' | ||
801 | local bom = "\239\187\191" | ||
802 | local shebang = "#!/usr/bin/env lua\n" | ||
803 | codes[#codes+1] = bom .. shebang .. "return true" | ||
804 | codes[#codes+1] = bom .. shebang .. bin | ||
805 | codes[#codes+1] = bom .. shebang .. "invalidsource" | ||
806 | codes[#codes+1] = bom .. shebang .. "\027invalidbinary" | ||
807 | for _,m in ipairs(modes) do | ||
808 | for i,c in ipairs(codes) do | ||
809 | print("loadfilex", m, i, F(mod.loadfile(c, m))) | ||
810 | end | ||
811 | end | ||
812 | end | ||
788 | ___'' | 813 | ___'' |
789 | 814 | ||