SemanticMediaWiki / SemanticScribunto

Provides service functions to support the Scribunto extension
Other
24 stars 14 forks source link

Fix getQueryResult to return table #3

Closed mint-thompson closed 8 years ago

mint-thompson commented 8 years ago

Wrap return value of getQueryResult in an array so that the entire result object will be transmitted.

mint-thompson commented 8 years ago

see #4

mwjames commented 8 years ago

Nice (Never thought someone would use this)

I think it will now break the test and while doing the array thing seems correct, the test requires to be rewritten.

1) LuaStandalone: SMW\Scribunto\Tests\ScribuntoLuaLibraryResultsTest[2]: getQueryResult (meta count)
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-{
-  "Modification date",
-}
+ERROR: attempt to index field 'printrequests' (a nil value)
    { name = 'getQueryResult (meta count)',
        func = function ( args )
          local ret =  mw.ext.smw.getQueryResult( args )
          return ret.printrequests[0].label
        end,
        args = { '[[Modification date::+]]|?Modification date|limit=0|mainlabel=-' },
        expect = { 'Modification date' }
    }
mwjames commented 8 years ago

I'm not that familiar with Lua but I think this should fix the test:

local testframework = require 'Module:TestFramework'

-- Tests
local tests = {
    --getQueryResult
    { name = 'getQueryResult (empty query)', func = mw.ext.smw.getQueryResult,
        args = { '' },
        expect = { nil }
    },
    { name = 'getQueryResult (printrequests label)',
        func = function ( args )
          local ret =  mw.ext.smw.getQueryResult( args )
            for k,v in pairs(ret.query.printrequests ) do
                return v.label
            end
        end,
        args = { '[[Modification date::+]]|?Modification date|limit=0|mainlabel=-' },
        expect = { 'Modification date' }
    }
}

return testframework.getTestProvider( tests )
mwjames commented 8 years ago

Thanks (tests pass now)

This change should be available by tomorrow on the sandbox.

cicalese commented 8 years ago

Thank you!