You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.5 KiB
48 lines
1.5 KiB
import { describe, expect, it } from '@jest/globals';
|
|
import { _ } from '../src/core';
|
|
import { fromChar as _c } from '../src/char';
|
|
import { toString as $s, fromString as _s } from '../src/string';
|
|
import { run } from '../src/bf';
|
|
|
|
describe('BF', () => {
|
|
describe('run', () => {
|
|
it('handles output command', () => {
|
|
expect($s(run._(_s('.'))._(_s('')))).toBe(String.fromCharCode(0));
|
|
});
|
|
|
|
it('handles input command', () => {
|
|
expect($s(run._(_s(',.'))._(_s('a')))).toBe('a');
|
|
});
|
|
|
|
it('handles inc command', () => {
|
|
expect($s(run._(_s('+.'))._(_s('')))).toBe(String.fromCharCode(1));
|
|
});
|
|
|
|
it('handles dec command', () => {
|
|
expect($s(run._(_s('-.'))._(_s('')))).toBe(String.fromCharCode(255));
|
|
});
|
|
|
|
it('handles next command', () => {
|
|
expect($s(run._(_s('+++++>++.'))._(_s('')))).toBe(String.fromCharCode(2));
|
|
});
|
|
|
|
it('handles prev command', () => {
|
|
expect($s(run._(_s('+++++>++<+++++.'))._(_s('')))).toBe(String.fromCharCode(10));
|
|
});
|
|
|
|
it('skips loop block on zero', () => {
|
|
expect($s(run._(_s('[+++++].'))._(_s('')))).toBe(String.fromCharCode(0));
|
|
});
|
|
|
|
it('repeats loop block while not zero', () => {
|
|
expect($s(run._(_s('+++++[-].'))._(_s('')))).toBe(String.fromCharCode(0));
|
|
});
|
|
|
|
it('prints "Hello World!"', () => {
|
|
expect($s(run
|
|
._(_s('++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.'))
|
|
._(_s(''))))
|
|
.toBe('Hello World!\n');
|
|
});
|
|
});
|
|
});
|
|
|