Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:VehicleHardpoint/testcases

From the Star Citizen Wiki, the fidelity™ encyclopedia
Module documentation[view][edit][history][purge]
This documentation is transcluded from Module:VehicleHardpoint/testcases/doc. Changes can be proposed in the talk page.
Function list
L 8 — suite:testSimpleEqRuleTrue
L 23 — suite:testSimpleEqRuleFalse
L 38 — suite:testSimpleMatchRuleTrue
L 53 — suite:testSimpleMatchRuleFalse
L 68 — suite:testSimpleAndEqRuleTrue
L 84 — suite:testSimpleAndEqRuleFalse
L 100 — suite:testNestedRuleTrue
L 124 — suite:testNestedRuleTrue2
L 148 — suite:testNestedRuleFalse
L 172 — suite:testApplyFixVtolThruster
L 225 — suite:testApplyConcatFix
👌 All tests passed.
Unit tests
Name Expected Actual
👌 testApplyConcatFix
👌 testApplyFixVtolThruster
👌 testNestedRuleFalse
👌 testNestedRuleTrue
👌 testNestedRuleTrue2
👌 testSimpleAndEqRuleFalse
👌 testSimpleAndEqRuleTrue
👌 testSimpleEqRuleFalse
👌 testSimpleEqRuleTrue
👌 testSimpleMatchRuleFalse
👌 testSimpleMatchRuleTrue

-- Unit tests for [[Module:VehicleHardpoint]]
local module = require( 'Module:VehicleHardpoint' )
local ScribuntoUnit = require( 'Module:ScribuntoUnit' )
local suite = ScribuntoUnit:new()


--- module.evalRule tests
function suite:testSimpleEqRuleTrue()
    local rule = [[
        [ "sub_type:FixedThruster" ]
    ]]
    rule = mw.text.jsonDecode( rule )

    local hardpoint = {
        sub_type = 'FixedThruster',
    }

    self:assertEquals( true, module.evalRule( rule, hardpoint ) )
end


--- module.evalRule tests
function suite:testSimpleEqRuleFalse()
    local rule = [[
        [ "sub_type:FixedThruster" ]
    ]]
    rule = mw.text.jsonDecode( rule )

    local hardpoint = {
        sub_type = 'FooBar',
    }

    self:assertEquals( false, module.evalRule( rule, hardpoint ) )
end


--- module.evalRule tests
function suite:testSimpleMatchRuleTrue()
    local rule = [[
        [ "sub_type:match:Fixed.*" ]
    ]]
    rule = mw.text.jsonDecode( rule )

    local hardpoint = {
        sub_type = 'FixedThruster',
    }

    self:assertEquals( true, module.evalRule( rule, hardpoint ) )
end


--- module.evalRule tests
function suite:testSimpleMatchRuleFalse()
    local rule = [[
        [ "sub_type:match:^StartFixed.+" ]
    ]]
    rule = mw.text.jsonDecode( rule )

    local hardpoint = {
        sub_type = 'FixedThruster',
    }

    self:assertEquals( false, module.evalRule( rule, hardpoint ) )
end


--- module.evalRule tests
function suite:testSimpleAndEqRuleTrue()
    local rule = [[
        [ "sub_type:FixedThruster", "and", "name:vtol" ]
    ]]
    rule = mw.text.jsonDecode( rule )

    local hardpoint = {
        sub_type = 'FixedThruster',
        name = 'vtol'
    }

    self:assertEquals( true, module.evalRule( rule, hardpoint ) )
end


--- module.evalRule tests
function suite:testSimpleAndEqRuleFalse()
    local rule = [[
        [ "sub_type:FixedThruster", "and", "name:vtol" ]
    ]]
    rule = mw.text.jsonDecode( rule )

    local hardpoint = {
        sub_type = 'FixedThruster',
        name = 'FooBar'
    }

    self:assertEquals( false, module.evalRule( rule, hardpoint ) )
end


--- module.evalRule tests
function suite:testNestedRuleTrue()
    local rule = [[
          [
            [ "sub_type:CountermeasureLauncher", "or", "sub_type:UNDEFINED" ],
            "and",
            [
              [ "class_name:find:decoy" ],
              "or",
              [ "class_name:find:flare" ]
            ]
          ]
    ]]
    rule = mw.text.jsonDecode( rule )

    local hardpoint = {
        sub_type = 'CountermeasureLauncher',
        class_name = 'DecoyLauncher'
    }

    self:assertEquals( true, module.evalRule( rule, hardpoint ) )
end


--- module.evalRule tests
function suite:testNestedRuleTrue2()
    local rule = [[
          [
            [ "sub_type:CountermeasureLauncher", "or", "sub_type:UNDEFINED" ],
            "and",
            [
              [ "class_name:find:decoy" ],
              "or",
              [ "class_name:find:flare" ]
            ]
          ]
    ]]
    rule = mw.text.jsonDecode( rule )

    local hardpoint = {
        sub_type = 'CountermeasureLauncher',
        class_name = 'FlareLauncher'
    }

    self:assertEquals( true, module.evalRule( rule, hardpoint ) )
end


--- module.evalRule tests
function suite:testNestedRuleFalse()
    local rule = [[
          [
            [ "sub_type:CountermeasureLauncher", "or", "sub_type:UNDEFINED" ],
            "and",
            [
              [ "class_name:find:decoy" ],
              "or",
              [ "class_name:find:flare" ]
            ]
          ]
    ]]
    rule = mw.text.jsonDecode( rule )

    local hardpoint = {
        sub_type = 'CountermeasureLauncher',
        class_name = 'FooLauncher'
    }

    self:assertEquals( false, module.evalRule( rule, hardpoint ) )
end


--- module.evalRule tests
function suite:testApplyFixVtolThruster()
    local fixes = [[
      [
        {
          "type": [ "ManneuverThruster", "MainThruster" ],
          "modification": [
            {
              "if": [
                [ "sub_type:FixedThruster", "or", "sub_type:UNDEFINED" ],
                "and",
                [ "name:match:vtol" ]
              ],
              "then": "sub_type=VtolThruster"
            },
            {
              "if": [
                [ "sub_type:FixedThruster", "or", "sub_type:UNDEFINED" ],
                "and",
                [ "name:match:retro" ]
              ],
              "then": "sub_type=RetroThruster"
            },
            {
              "if": [
                [ "sub_type:JointThruster", "or", "sub_type:UNDEFINED" ],
                "and",
                [ "name:match:vtol" ]
              ],
              "then": "sub_type=GravLev"
            },
            {
              "if": [ "type:MainThruster" ],
              "then": "sub_type=Main+sub_type"
            }
          ]
        }
      ]
    ]]
    fixes = mw.text.jsonDecode( fixes )

    local hardpoint = {
        type = 'ManneuverThruster',
        sub_type = 'FixedThruster',
        name = 'hardpoint_mav_vtol_thruster'
    }

    module.fixTypes( hardpoint, fixes )

    self:assertEquals( 'VtolThruster', hardpoint.sub_type )
end


--- module.evalRule tests
function suite:testApplyConcatFix()
    local fixes = [[
      [
        {
          "type": [ "ManneuverThruster", "MainThruster" ],
          "modification": [
            {
              "if": [ "type:MainThruster" ],
              "then": "sub_type=Main+sub_type"
            }
          ]
        }
      ]
    ]]
    fixes = mw.text.jsonDecode( fixes )

    local hardpoint = {
        type = 'MainThruster',
        sub_type = 'FixedThruster',
    }

    module.fixTypes( hardpoint, fixes )

    self:assertEquals( 'MainFixedThruster', hardpoint.sub_type )
end



return suite
Heya! We only use cookie to make the site function and save your preferences, nothing else :)