Last active
April 25, 2017 13:12
-
-
Save CaptainPRICE/a562800a002a7255ddb8f7d7af1f6ca6 to your computer and use it in GitHub Desktop.
Expression 2 test code for https://github.com/wiremod/wire/pull/1366
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @name Namer-Test-Code | |
| @persist ENTITY:entity [BigString1 BigString2]:string | |
| if (first()) | |
| { | |
| ENTITY = entity() | |
| print("Test: entity:setName(string)") | |
| print(setName("Namer-Test-Code") == 0) # Pass [initially, the names are the same so it is expected to fail] | |
| print(setName("Another E2 Name") == 1) # Pass [name is successfully changed] | |
| print(ENTITY:setName("") == 1) # Pass [empty string will change the name to "generic"] | |
| print(ENTITY:setName("generic") == 0) # Pass [should fail because it is already "generic"] | |
| print(ENTITY:getName() == "generic") # Pass [yes the name should be "generic"] | |
| print("Test: Default entity:getComponentName") | |
| print(ENTITY:getComponentName() == "Wire Expression 2") # Pass [by default E2 component name is "Wire Expression 2"] | |
| print("Test: entity:setComponentName(string)") | |
| print(ENTITY:setComponentName("New Component Name") == 1) # Pass [component name is successfully changed] | |
| print(ENTITY:getComponentName() == "New Component Name") # Pass [they should match up] | |
| print(ENTITY:setComponentName("") == 1) # Pass [using an empty string should restore it back to the original component name] | |
| print(ENTITY:setComponentName("Wire Expression 2") == 0) # Pass [should fail because it is already "Wire Expression 2"] | |
| print(ENTITY:getComponentName() == "Wire Expression 2") # Pass [yes the component name should be "Wire Expression 2"] | |
| local Dots = ("."):repeat(200) | |
| print(entity():setComponentName(Dots) == 0) # Pass [should fail because of the limit of 199 characters] | |
| BigString1 = ("1"):repeat(199) | |
| BigString2 = ("2"):repeat(199) | |
| timer("Anti-Spam-Test", 1000) | |
| } | |
| elseif (clk("Anti-Spam-Test")) | |
| { | |
| # NOTE: I have tested this with the limit-per-second being 597 instead of 12000; It works as expected. | |
| print("Test: Anti-Spam for entity:setComponentName(string) function") | |
| print(entity():setComponentName(BigString1) == 1) # Pass [component name is successfully changed; total upload length: 199] | |
| print(entity():setComponentName(BigString2) == 1) # Pass [component name is successfully changed; total upload length: 398] | |
| print(entity():setComponentName(BigString1) == 1) # Pass [component name is successfully changed; total upload length: 597] | |
| print(entity():setComponentName("X") == 0) # Pass [should fail because of the limit of 597 characters per second] | |
| print(entity():getComponentName():length() == BigString1:length()) # Pass [verify the length is still 199 as it should be] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment