diff options
author | Remko Tronçon <git@el-tramo.be> | 2013-08-25 16:39:06 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2013-08-27 19:47:48 (GMT) |
commit | 1bb607f96e79845ce30dd5590b0d53cc394ac150 (patch) | |
tree | 6156622ddd1b3238aec73536e0dc25b632965a71 /Sluift/Tests | |
parent | c4431ee90f3f1daac0a12b35bfa3378d5c570eaa (diff) | |
download | swift-contrib-1bb607f96e79845ce30dd5590b0d53cc394ac150.zip swift-contrib-1bb607f96e79845ce30dd5590b0d53cc394ac150.tar.bz2 |
PubSub implementation & Sluift refactoring.
Change-Id: I04ff7111b73565c00bff6db183451774a633344f
Diffstat (limited to 'Sluift/Tests')
-rw-r--r-- | Sluift/Tests/ConnectTest.lua | 6 | ||||
-rw-r--r-- | Sluift/Tests/DOMTest.lua | 14 | ||||
-rw-r--r-- | Sluift/Tests/FormTest.lua | 73 |
3 files changed, 93 insertions, 0 deletions
diff --git a/Sluift/Tests/ConnectTest.lua b/Sluift/Tests/ConnectTest.lua new file mode 100644 index 0000000..0afa3fa --- /dev/null +++ b/Sluift/Tests/ConnectTest.lua @@ -0,0 +1,6 @@ +-- Test connect with function parameter +client = sluift.new_client(os.getenv("SLUIFT_JID"), os.getenv("SLUIFT_PASS")) +x, y, z = client:connect(function (c) return 1, '2', true end) +assert(x == 1) +assert(y == '2') +assert(z == true) diff --git a/Sluift/Tests/DOMTest.lua b/Sluift/Tests/DOMTest.lua new file mode 100644 index 0000000..0c31183 --- /dev/null +++ b/Sluift/Tests/DOMTest.lua @@ -0,0 +1,14 @@ +t = sluift.from_xml([[ + <foo xmlns='http://swift.im/test' myattr1='myval1' myattr2='myval2'> + <bar myattr3='myval3'> + <baz/> + </bar> + Some Text + <bam myattr4='myval4'> + Some other text + </bam> + </foo> +]]) + +print(t) +print(sluift.to_xml(t)) diff --git a/Sluift/Tests/FormTest.lua b/Sluift/Tests/FormTest.lua new file mode 100644 index 0000000..813e05c --- /dev/null +++ b/Sluift/Tests/FormTest.lua @@ -0,0 +1,73 @@ +--[[ + Copyright (c) 2013 Remko Tronçon + Licensed under the GNU General Public License v3. + See Documentation/Licenses/GPLv3.txt for more information. +--]] + +example_form = [[ +<x xmlns='jabber:x:data' type='form'> + <title>Bot Configuration</title> + <instructions>Fill out this form to configure your new bot!</instructions> + <field type='hidden' var='FORM_TYPE'> + <value>jabber:bot</value> + </field> + <field type='fixed'><value>Section 1: Bot Info</value></field> + <field type='text-single' label='The name of your bot' var='botname'/> + <field type='text-multi' label='Helpful description of your bot' var='description'/> + <field type='boolean' label='Public bot?' var='public'> + <required/> + </field> + <field type='text-private' label='Password for special access' var='password'/> + <field type='fixed'><value>Section 2: Features</value></field> + <field type='list-multi' label='What features will the bot support?' var='features'> + <option label='Contests'><value>contests</value></option> + <option label='News'><value>news</value></option> + <option label='Polls'><value>polls</value></option> + <option label='Reminders'><value>reminders</value></option> + <option label='Search'><value>search</value></option> + <value>news</value> + <value>search</value> + </field> + <field type='fixed'><value>Section 3: Subscriber List</value></field> + <field type='list-single' label='Maximum number of subscribers' var='maxsubs'> + <value>20</value> + <option label='10'><value>10</value></option> + <option label='20'><value>20</value></option> + <option label='30'><value>30</value></option> + <option label='50'><value>50</value></option> + <option label='100'><value>100</value></option> + <option label='None'><value>none</value></option> + </field> + <field type='fixed'><value>Section 4: Invitations</value></field> + <field type='jid-multi' label='People to invite' var='invitelist'> + <desc>Tell all your friends about your new bot!</desc> + </field> +</x>]] + +form = sluift.from_xml(example_form)['data'] +print(form) + +-- Test form properties +assert(form['title'] == 'Bot Configuration') + +-- Test boolean field +public_field = form['fields'][5] +assert(public_field['name'] == 'public') +assert(type(public_field['value']) == 'boolean') +assert(public_field['required'] == true) + +-- Test multi field +features_field = form['fields'][8] +assert(features_field['name'] == 'features') +assert(type(features_field['values']) == 'table') +assert(#features_field['values'] == 2) +assert(features_field['values'][1] == 'news') +assert(features_field['values'][2] == 'search') + +-- Test shortcut index +assert(form['features']['name'] == 'features') +assert(form['FORM_TYPE']['value'] == 'jabber:bot') + +-- Test response form +print(form:create_submission()) +--print(sluift.to_xml({type = 'form', data = form})) |