I think this hypothetical might miss the point of the comment it's replying to. In my mind, cheating requires intention. Now, it would be hard for the student to disprove that any of these situations were not intentional but if for example the student studied Rosetta for the exam, it's very possible the student just memorized the code and didn't reference it during the test. Is that still cheating?
Cheating does not require intent. That is, the university only has to prove that the student's work is not original to conclude that plagiarism and also cheating has occurred. Memorization is usually not prohibited in exams.