Skip to content

Add test of text with a single quote

Maia Xiao requested to merge (removed):mxo-main-patch-78232 into main

This MR adds a test in Chapter 4 to make sure that strings with single quotes in them are printed correctly. It avoids the situation where this bug would not be caught until future chapters.

In Python, repr('hello') returns 'hello', but for a string with a single quote — like repr('hellon\'t'), it knows to wrap it around with double quotes instead and hence would return something like "hellon't".

We write the __repr__(self) method for the Text class in Chapter 4, and I had a bug then where I manually wrapped strings around with the ' character. The bug is because I tried to manually construct a string instead of just returning repr(self.text). For me, this bug would not bug caught until Chapter 5:

Expected:
     <html>
       <head>
         <title>
           'Chapter5'
         <script>
           "Don't display me"
       <body>
         'Do display me'
Got:
     <html>
       <head>
         <title>
           'Chapter5'
         <script>
           'Don't display me'
       <body>
         'Do display me'```
Edited by Maia Xiao

Merge request reports