{"action":"created","issue":{"url":"https://api.github.com/repos/bonecode/TBCEditor/issues/315","repository_url":"https://api.github.com/repos/bonecode/TBCEditor","labels_url":"https://api.github.com/repos/bonecode/TBCEditor/issues/315/labels{/name}","comments_url":"https://api.github.com/repos/bonecode/TBCEditor/issues/315/comments","events_url":"https://api.github.com/repos/bonecode/TBCEditor/issues/315/events","html_url":"https://github.com/bonecode/TBCEditor/issues/315","id":132075529,"number":315,"title":"Undo issues + Monkey tester","user":{"login":"EricGrange","id":2197210,"avatar_url":"https://avatars.githubusercontent.com/u/2197210?v=3","gravatar_id":"","url":"https://api.github.com/users/EricGrange","html_url":"https://github.com/EricGrange","followers_url":"https://api.github.com/users/EricGrange/followers","following_url":"https://api.github.com/users/EricGrange/following{/other_user}","gists_url":"https://api.github.com/users/EricGrange/gists{/gist_id}","starred_url":"https://api.github.com/users/EricGrange/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/EricGrange/subscriptions","organizations_url":"https://api.github.com/users/EricGrange/orgs","repos_url":"https://api.github.com/users/EricGrange/repos","events_url":"https://api.github.com/users/EricGrange/events{/privacy}","received_events_url":"https://api.github.com/users/EricGrange/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/bonecode/TBCEditor/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":15,"created_at":"2016-02-08T07:53:50Z","updated_at":"2016-02-09T08:37:38Z","closed_at":null,"body":"Below is a quick & dirty monkey tester, feel free to improve and add more commands :)\r\n\r\nTo have it compile, on a form with an \"Editor\" component, drop a BBMonkey button and attach it to the following event code. Here it fails at RandSeed = 293, but YMMV. It attempts only 3 commands before undoing them and checking for damage.\r\n\r\nI guess once it's stable up to a few dozen commands and a hundred thousand runs, it could be worth expanding cCommands to include more actions (like undo, copy-paste, etc.), right now it's just caret input, caret movements and selection extension.\r\n\r\nIn the much longer run, this could be graduated to a full blown fuzz tester.\r\n\r\n```\r\nprocedure TForm93.BBMonkeyClick(Sender: TObject);\r\nconst\r\n   cCommands : array [0..8] of Integer = (\r\n      ecLeft, ecRight, ecUp, ecDown,\r\n      ecSelectionLeft, ecSelectionRight, ecSelectionUp, ecSelectionDown,\r\n      ecChar\r\n      );\r\n   cNBActions = 3;\r\nvar\r\n   s : TStringStream;\r\n   i, j, cmd : Integer;\r\n   buf, ident : String;\r\nbegin\r\n   for i:=1 to 10000 do begin\r\n\r\n      Editor.Clear;\r\n      s:=TStringStream.Create('1'#13#10'2'#13#10'3'#13#10'4'#13#10'5'#13#10);\r\n      Editor.LoadFromStream(s);\r\n      s.Free;\r\n     \r\n      RandSeed:=i;\r\n      for j:=1 to cNBActions do begin\r\n         Editor.ExecuteCommand(cCommands[Random(Length(cCommands))], 'a', nil);\r\n      end;\r\n\r\n      for j:=1 to cNBActions do\r\n         Editor.ExecuteCommand(ecUndo, #0, nil);\r\n\r\n      if Editor.Lines.CommaText <> '1,2,3,4,5' then begin\r\n         BBMonkey.Caption := Editor.Lines.CommaText;\r\n         buf:='';\r\n         RandSeed:=i;\r\n         for j:=1 to cNBActions do begin\r\n            cmd:=cCommands[Random(Length(cCommands))];\r\n            EditorCommandToIdent(cmd, ident);\r\n            buf := buf + ', '+ ident;\r\n         end;\r\n         Caption := 'Failed for RandSeed = '+IntToStr(i)+buf;\r\n         Clipboard.AsText := buf;\r\n         Break;\r\n      end;\r\n\r\n   end;\r\nend;\r\n\r\n```\r\n\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/bonecode/TBCEditor/issues/comments/181759991","html_url":"https://github.com/bonecode/TBCEditor/issues/315#issuecomment-181759991","issue_url":"https://api.github.com/repos/bonecode/TBCEditor/issues/315","id":181759991,"user":{"login":"EricGrange","id":2197210,"avatar_url":"https://avatars.githubusercontent.com/u/2197210?v=3","gravatar_id":"","url":"https://api.github.com/users/EricGrange","html_url":"https://github.com/EricGrange","followers_url":"https://api.github.com/users/EricGrange/followers","following_url":"https://api.github.com/users/EricGrange/following{/other_user}","gists_url":"https://api.github.com/users/EricGrange/gists{/gist_id}","starred_url":"https://api.github.com/users/EricGrange/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/EricGrange/subscriptions","organizations_url":"https://api.github.com/users/EricGrange/orgs","repos_url":"https://api.github.com/users/EricGrange/repos","events_url":"https://api.github.com/users/EricGrange/events{/privacy}","received_events_url":"https://api.github.com/users/EricGrange/received_events","type":"User","site_admin":false},"created_at":"2016-02-09T08:37:38Z","updated_at":"2016-02-09T08:37:38Z","body":"Hmm, then there may be another bug lurking, the extra space should have happened given soPastEndOfLine is enabled by default, or is there an option to trim EOL spaces that is somehow ste somewhere?\r\n\r\nFor better reproduceability, I create the editor in code, maybe if you created it in the DFM in Delphi and some of the option in that case do not match those of the source code?"}}