diff options
| author | Uri Shaked | 2019-12-07 13:08:46 +0200 |
|---|---|---|
| committer | Uri Shaked | 2019-12-07 13:08:46 +0200 |
| commit | 92898c67a4da42992a8115ffa7b12781e49f2eae (patch) | |
| tree | 00e94786829b3c2cef833e94b45efb393be06b6d /src/usart.spec.ts | |
| parent | chore: update package-lock.json (diff) | |
| download | avr8js-92898c67a4da42992a8115ffa7b12781e49f2eae.tar.gz avr8js-92898c67a4da42992a8115ffa7b12781e49f2eae.tar.bz2 avr8js-92898c67a4da42992a8115ffa7b12781e49f2eae.zip | |
feat(usart): add onLineTransmit callback
Diffstat (limited to 'src/usart.spec.ts')
| -rw-r--r-- | src/usart.spec.ts | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/usart.spec.ts b/src/usart.spec.ts index f0dacc4..dadfc78 100644 --- a/src/usart.spec.ts +++ b/src/usart.spec.ts @@ -113,4 +113,47 @@ describe('USART', () => { expect(cpu.data[0xc0]).toEqual(0x40 | 0x20); // UCSR0A: TXC | UDRE }); }); + + describe('onLineTransmit', () => { + it('should call onLineTransmit with the current line buffer after every newline', () => { + const cpu = new CPU(new Uint16Array(1024)); + const usart = new AVRUSART(cpu, usart0Config, FREQ_16MHZ); + usart.onLineTransmit = jest.fn(); + cpu.writeData(0xc1, 0x8); // UCSR0B <- TXEN + cpu.writeData(0xc6, 0x48); // 'H' + cpu.writeData(0xc6, 0x65); // 'e' + cpu.writeData(0xc6, 0x6c); // 'l' + cpu.writeData(0xc6, 0x6c); // 'l' + cpu.writeData(0xc6, 0x6f); // 'o' + cpu.writeData(0xc6, 0xa); // '\n' + expect(usart.onLineTransmit).toHaveBeenCalledWith('Hello'); + }); + + it('should not call onLineTransmit if no newline was received', () => { + const cpu = new CPU(new Uint16Array(1024)); + const usart = new AVRUSART(cpu, usart0Config, FREQ_16MHZ); + usart.onLineTransmit = jest.fn(); + cpu.writeData(0xc1, 0x8); // UCSR0B <- TXEN + cpu.writeData(0xc6, 0x48); // 'H' + cpu.writeData(0xc6, 0x69); // 'i' + expect(usart.onLineTransmit).not.toHaveBeenCalled(); + }); + + it('should clear the line buffer after each call to onLineTransmit', () => { + const cpu = new CPU(new Uint16Array(1024)); + const usart = new AVRUSART(cpu, usart0Config, FREQ_16MHZ); + usart.onLineTransmit = jest.fn(); + cpu.writeData(0xc1, 0x8); // UCSR0B <- TXEN + cpu.writeData(0xc6, 0x48); // 'H' + cpu.writeData(0xc6, 0x69); // 'i' + cpu.writeData(0xc6, 0xa); // '\n' + cpu.writeData(0xc6, 0x74); // 't' + cpu.writeData(0xc6, 0x68); // 'h' + cpu.writeData(0xc6, 0x65); // 'e' + cpu.writeData(0xc6, 0x72); // 'r' + cpu.writeData(0xc6, 0x65); // 'e' + cpu.writeData(0xc6, 0xa); // '\n' + expect(usart.onLineTransmit).toHaveBeenCalledWith('there'); + }); + }); }); |
