mirror of
				https://github.com/SquidDev-CC/CC-Tweaked
				synced 2025-10-30 21:23:00 +00:00 
			
		
		
		
	Fix 0 being treated as a valid colour (#2211)
This commit is contained in:
		| @@ -371,7 +371,7 @@ function toBlit(color) | ||||
|     local hex = color_hex_lookup[color] | ||||
|     if hex then return hex end | ||||
|  | ||||
|     if color < 0 or color > 0xffff then error("Colour out of range", 2) end | ||||
|     if color < 1 or color > 0xffff then error("Colour out of range", 2) end | ||||
|     return string.format("%x", math.floor(math.log(color, 2))) | ||||
| end | ||||
|  | ||||
|   | ||||
| @@ -65,7 +65,7 @@ local function parse_color(color) | ||||
|         return expect(1, color, "number") | ||||
|     end | ||||
|  | ||||
|     if color < 0 or color > 0xffff then error("Colour out of range", 3) end | ||||
|     if color < 1 or color > 0xffff then error("Colour out of range", 3) end | ||||
|     return 2 ^ math.floor(math.log(color, 2)) | ||||
| end | ||||
|  | ||||
|   | ||||
| @@ -94,6 +94,7 @@ describe("The colors library", function() | ||||
|         end) | ||||
|  | ||||
|         it("errors on out-of-range colours", function() | ||||
|             expect.error(colors.toBlit, 0):eq("Colour out of range") | ||||
|             expect.error(colors.toBlit, -120):eq("Colour out of range") | ||||
|             expect.error(colors.toBlit, 0x10000):eq("Colour out of range") | ||||
|         end) | ||||
|   | ||||
| @@ -59,6 +59,16 @@ describe("The window library", function() | ||||
|  | ||||
|             expect.error(w.setTextColour, nil):eq("bad argument #1 (number expected, got nil)") | ||||
|             expect.error(w.setTextColour, -5):eq("Colour out of range") | ||||
|             expect.error(w.setTextColour, 0):eq("Colour out of range") | ||||
|             expect.error(w.setTextColour, 0x10000):eq("Colour out of range") | ||||
|         end) | ||||
|  | ||||
|         it("accepts valid colours", function() | ||||
|             local w = mk() | ||||
|             for i = 0, 15 do | ||||
|                 w.setBackgroundColour(2 ^ i) | ||||
|                 expect(w.getBackgroundColour()):eq(2 ^ i) | ||||
|             end | ||||
|         end) | ||||
|  | ||||
|         it("supports invalid combined colours", function() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 SpartanSoftware
					SpartanSoftware