add test: cyclic text
move scan()'s core logic to Context class