Repository: mozilla/pdf.js
File: test/unit/image_utils_spec.js (JavaScript)

Code before:
        kind: ImageKind.GRAYSCALE_1BPP,
      });
      expect(result).not.toBeNull();
      expect(result.destPos).toEqual(8);

      const dest32 = new Uint32Array(dest.buffer);
      expect(dest32[0]).toEqual(WHITE);
      expect(dest32[4]).toEqual(BLACK);
    });

    it("dispatches to convertRGBToRGBA for RGB_24BPP", function () {
      // Three pixels: white, black, red.
      const src = new Uint8Array([255, 255, 255, 0, 0, 0, 255, 0, 0]);
      const dest = new Uint32Array(3);
      const result = convertToRGBA({
        src,
        dest,
        width: 3,
        height: 1,
        kind: ImageKind.RGB_24BPP,
      });
      expect(result).not.toBeNull();
      expect(result.srcPos).toEqual(9);
      expect(result.destPos).toEqual(3);

      expect(dest[0]).toEqual(0xffffffff); // white is the same in both endiannesses
      if (isLE) {
        expect(dest[1]).toEqual(0xff000000); // black
        expect(dest[2]).toEqual(0xff0000ff); // red
      } else {
        expect(dest[1]).toEqual(0x000000ff); // black
        expect(dest[2]).toEqual(0xff0000ff); // red
      }
    });

    it("returns null for an unknown kind", function () {
      const result = convertToRGBA({
        src: new Uint8Array(4),
        dest: new Uint32Array(1),
        width: 1,
        height: 1,
        kind: 999,
      });
      expect(result).toBeNull();
    });

    it("handles destPos offset for RGB_24BPP", function () {
      // One red pixel written at destPos=2 in a 4-pixel buffer.
      const src = new Uint8Array([255, 0, 0]);
      const dest = new Uint32Array(4);
      const result = convertToRGBA({

Review comment (suggestion):
Same comment here to use the `BLACK` and `WHITE` constants with a ternary for red to remove the `if` statement and have a single set of assertions.

Code after:
      const dest32 = new Uint32Array(dest.buffer);
      expect(dest32[0]).toEqual(WHITE);
      expect(dest32[4]).toEqual(BLACK);
    });

    it("dispatches to convertRGBToRGBA for RGB_24BPP", function () {
      // Three pixels: white, black, red.
      const src = new Uint8Array([255, 255, 255, 0, 0, 0, 255, 0, 0]);
      const dest = new Uint32Array(3);
      const result = convertToRGBA({
        src,
        dest,
        width: 3,
        height: 1,
        kind: ImageKind.RGB_24BPP,
      });
      expect(result).not.toBeNull();
      expect(result.srcPos).toEqual(9);
      expect(result.destPos).toEqual(3);

      expect(dest[0]).toEqual(WHITE);
      expect(dest[1]).toEqual(BLACK);
      expect(dest[2]).toEqual(RED);
    });

    it("returns null for an unknown kind", function () {
      const result = convertToRGBA({
        src: new Uint8Array(4),
        dest: new Uint32Array(1),
        width: 1,
        height: 1,
        kind: 999,
      });
      expect(result).toBeNull();
    });

    it("handles destPos offset for RGB_24BPP", function () {
      // One red pixel written at destPos=2 in a 4-pixel buffer.
      const src = new Uint8Array([255, 0, 0]);
      const dest = new Uint32Array(4);
      const result = convertToRGBA({
        src,
        dest,
        destPos: 2,
        width: 1,
        height: 1,
        kind: ImageKind.RGB_24BPP,
      });
      expect(result.destPos).toEqual(3);
      expect(dest[0]).toEqual(0); // untouched
      expect(dest[1]).toEqual(0); // untouched