Repository: Qiskit/qiskit

Issue:
text drawer bug in drawing conditional multi-qubit gates
<!-- ⚠️ If you do not respect this template, your issue will be closed -->
<!-- ⚠️ Make sure to browse the opened and closed issues -->

### Information

- **Qiskit Terra version**:
- **Python version**:
- **Operating system**:

### What is the current behavior?
Conditional versions of 2-qubit or 3-qubit gates are drawn incorrectly in the text drawer. The box is drawn on only one of the qubits, whereas it should be 2 or 3 qubits.
```python
qr = QuantumRegister(3, 'qr')
cr = ClassicalRegister(2, 'cr')
circuit = QuantumCircuit(qr, cr)
circuit.cz(qr[0], qr[1]).c_if(cr, 1)
circuit.ccx(qr[0], qr[1], qr[2]).c_if(cr, 3)
```
```
          ┌────┐┌─────┐
qr_0: |0>─┤ Cz ├┤ Ccx ├
          └─┬──┘└──┬──┘
qr_1: |0>───┼──────┼───
            │      │   
qr_2: |0>───┼──────┼───
         ┌──┴──┐┌──┴──┐
 cr_0: 0 ╡     ╞╡     ╞
         │ = 1 ││ = 3 │
 cr_1: 0 ╡     ╞╡     ╞
         └─────┘└─────┘
```

### What is the expected behavior?
The mpl and latex drawers draw these correctly:

![image](https://user-images.githubusercontent.com/8622381/56842662-b4740a00-6865-11e9-961c-f81ffbc17e71.png)

![image](https://user-images.githubusercontent.com/8622381/56842667-bccc4500-6865-11e9-827b-5a125ed6da06.png)





Discussion:

Resolving patch:
diff --git a/qiskit/visualization/text.py b/qiskit/visualization/text.py
--- a/qiskit/visualization/text.py
+++ b/qiskit/visualization/text.py
@@ -136,14 +136,14 @@ class BoxOnQuWire(DrawElement):
         bot: └───┘   └───┘
     """
 
-    def __init__(self, label="", top_connect='─', bot_connect='─'):
+    def __init__(self, label="", top_connect='─', conditional=False):
         super().__init__(label)
         self.top_format = "┌─%s─┐"
         self.mid_format = "┤ %s ├"
         self.bot_format = "└─%s─┘"
         self.top_pad = self.bot_pad = self.mid_bck = '─'
         self.top_connect = top_connect
-        self.bot_connect = bot_connect
+        self.bot_connect = '┬' if conditional else '─'
         self.mid_content = label
         self.top_connector = {"│": '┴'}
         self.bot_connector = {"│": '┬'}
@@ -244,15 +244,15 @@ def __init__(self, label, input_length, order, wire_label=''):
 class BoxOnQuWireBot(MultiBox, BoxOnQuWire):
     """ Draws the bottom part of a box that affects more than one quantum wire"""
 
-    def __init__(self, label, input_length, bot_connect='─', wire_label=''):
+    def __init__(self, label, input_length, bot_connect='─', wire_label='', conditional=False):
         super().__init__(label)
         self.wire_label = wire_label
         self.top_pad = " "
         self.left_fill = len(self.wire_label)
         self.top_format = "│{} %s │".format(self.top_pad * self.left_fill)
         self.mid_format = "┤{} %s ├".format(self.wire_label)
-        self.bot_format = "└{}─%s─┘".format(self.bot_pad * self.left_fill)
-        self.bot_connect = bot_connect
+        self.bot_format = "└{}%s──┘".format(self.bot_pad * self.left_fill)
+        self.bot_connect = '┬' if conditional else bot_connect
 
         self.mid_content = self.top_connect = ""
         if input_length <= 2:
@@ -287,7 +287,7 @@ def __init__(self, label, input_length, order, wire_label=''):
 class BoxOnClWireBot(MultiBox, BoxOnClWire):
     """ Draws the bottom part of a conditional box that affects more than one classical wire"""
 
-    def __init__(self, label, input_length, bot_connect='─', wire_label=''):
+    def __init__(self, label, input_length, bot_connect='─', wire_label='', **_):
         super().__init__(label)
         self.wire_label = wire_label
         self.top_format = "│ %s │"
@@ -336,17 +336,19 @@ class Ex(DirectOnQuWire):
     bot:  │     │
     """
 
-    def __init__(self, bot_connect=" ", top_connect=" "):
+    def __init__(self, bot_connect=" ", top_connect=" ", conditional=False):
         super().__init__("X")
-        self.bot_connect = bot_connect
+        self.bot_connect = "│" if conditional else bot_connect
         self.top_connect = top_connect
 
 
 class Reset(DirectOnQuWire):
     """ Draws a reset gate"""
 
-    def __init__(self):
+    def __init__(self, conditional=False):
         super().__init__("|0>")
+        if conditional:
+            self.bot_connect = "│"
 
 
 class Bullet(DirectOnQuWire):
@@ -356,10 +358,10 @@ class Bullet(DirectOnQuWire):
     bot:  │      │
     """
 
-    def __init__(self, top_connect="", bot_connect=""):
+    def __init__(self, top_connect="", bot_connect="", conditional=False):
         super().__init__('■')
         self.top_connect = top_connect
-        self.bot_connect = bot_connect
+        self.bot_connect = '│' if conditional else bot_connect
         self.mid_bck = '─'
 
 
@@ -718,6 +720,13 @@ def _instruction_to_gate(self, instruction, layer):
 
         current_cons = []
         connection_label = None
+        conditional = False
+
+        if instruction.condition is not None:
+            # conditional
+            cllabel = TextDrawing.label_for_conditional(instruction)
+            layer.set_cl_multibox(instruction.condition[0], cllabel, top_connect='┴')
+            conditional = True
 
         # add in a gate that operates over multiple qubits
         def add_connected_gate(instruction, gates, layer, current_cons):
@@ -742,75 +751,70 @@ def add_connected_gate(instruction, gates, layer, current_cons):
 
         elif instruction.name == 'swap':
             # swap
-            gates = [Ex() for _ in range(len(instruction.qargs))]
+            gates = [Ex(conditional=conditional) for _ in range(len(instruction.qargs))]
             add_connected_gate(instruction, gates, layer, current_cons)
 
         elif instruction.name == 'cswap':
             # cswap
-            gates = [Bullet(), Ex(), Ex()]
+            gates = [Bullet(conditional=conditional),
+                     Ex(conditional=conditional),
+                     Ex(conditional=conditional)]
             add_connected_gate(instruction, gates, layer, current_cons)
 
         elif instruction.name == 'reset':
-            layer.set_qubit(instruction.qargs[0], Reset())
-
-        elif instruction.condition is not None:
-            # conditional
-            cllabel = TextDrawing.label_for_conditional(instruction)
-            qulabel = TextDrawing.label_for_box(instruction)
-
-            layer.set_cl_multibox(instruction.condition[0], cllabel, top_connect='┴')
-            layer.set_qubit(instruction.qargs[0], BoxOnQuWire(qulabel, bot_connect='┬'))
+            layer.set_qubit(instruction.qargs[0], Reset(conditional=conditional))
 
         elif instruction.name in ['cx', 'CX', 'ccx']:
             # cx/ccx
-            gates = [Bullet() for _ in range(len(instruction.qargs) - 1)]
-            gates.append(BoxOnQuWire('X'))
+            gates = [Bullet(conditional=conditional) for _ in range(len(instruction.qargs) - 1)]
+            gates.append(BoxOnQuWire('X', conditional=conditional))
             add_connected_gate(instruction, gates, layer, current_cons)
 
         elif instruction.name == 'cy':
             # cy
-            gates = [Bullet(), BoxOnQuWire('Y')]
+            gates = [Bullet(conditional=conditional), BoxOnQuWire('Y')]
             add_connected_gate(instruction, gates, layer, current_cons)
 
         elif instruction.name == 'cz':
             # cz
-            gates = [Bullet(), Bullet()]
+            gates = [Bullet(conditional=conditional), Bullet(conditional=conditional)]
             add_connected_gate(instruction, gates, layer, current_cons)
 
         elif instruction.name == 'ch':
             # ch
-            gates = [Bullet(), BoxOnQuWire('H')]
+            gates = [Bullet(conditional=conditional), BoxOnQuWire('H')]
             add_connected_gate(instruction, gates, layer, current_cons)
 
         elif instruction.name == 'cu1':
             # cu1
             connection_label = TextDrawing.params_for_label(instruction)[0]
-            gates = [Bullet(), Bullet()]
+            gates = [Bullet(conditional=conditional), Bullet(conditional=conditional)]
             add_connected_gate(instruction, gates, layer, current_cons)
 
         elif instruction.name == 'rzz':
             # rzz
             connection_label = "zz(%s)" % TextDrawing.params_for_label(instruction)[0]
-            gates = [Bullet(), Bullet()]
+            gates = [Bullet(conditional=conditional), Bullet(conditional=conditional)]
             add_connected_gate(instruction, gates, layer, current_cons)
 
         elif instruction.name == 'cu3':
             # cu3
             params = TextDrawing.params_for_label(instruction)
-            gates = [Bullet(), BoxOnQuWire("U3(%s)" % ','.join(params))]
+            gates = [Bullet(conditional=conditional),
+                     BoxOnQuWire("U3(%s)" % ','.join(params), conditional=conditional)]
             add_connected_gate(instruction, gates, layer, current_cons)
 
         elif instruction.name == 'crz':
             # crz
             label = "Rz(%s)" % TextDrawing.params_for_label(instruction)[0]
-
-            gates = [Bullet(), BoxOnQuWire(label)]
+            gates = [Bullet(conditional=conditional), BoxOnQuWire(label, conditional=conditional)]
             add_connected_gate(instruction, gates, layer, current_cons)
 
         elif len(instruction.qargs) == 1 and not instruction.cargs:
             # unitary gate
             layer.set_qubit(instruction.qargs[0],
-                            BoxOnQuWire(TextDrawing.label_for_box(instruction)))
+                            BoxOnQuWire(TextDrawing.label_for_box(instruction),
+                                        conditional=conditional))
 
         elif len(instruction.qargs) >= 2 and not instruction.cargs:
             # multiple qubit gate
@@ -818,7 +822,7 @@ def add_connected_gate(instruction, gates, layer, current_cons):
             params = TextDrawing.params_for_label(instruction)
             if params:
                 label += "(%s)" % ','.join(params)
-            layer.set_qu_multibox(instruction.qargs, label)
+            layer.set_qu_multibox(instruction.qargs, label, conditional=conditional)
 
         else:
             raise VisualizationError(
@@ -896,7 +900,7 @@ def set_clbit(self, clbit, element):
         """
         self.clbit_layer[self.cregs.index(clbit)] = element
 
-    def _set_multibox(self, wire_type, bits, label, top_connect=None):
+    def _set_multibox(self, wire_type, bits, label, top_connect=None, conditional=False):
         bits = list(bits)
         if wire_type == "cl":
             bit_index = sorted([i for i, x in enumerate(self.cregs) if x in bits])
@@ -933,7 +937,8 @@ def _set_multibox(self, wire_type, bits, label, top_connect=None):
                     named_bit = (self.qregs + self.cregs)[bit_i]
                     wire_label = ' ' * len(qargs[0])
                 set_bit(named_bit, BoxOnWireMid(label, box_height, order, wire_label=wire_label))
-            set_bit(bits.pop(0), BoxOnWireBot(label, box_height, wire_label=qargs.pop(0)))
+            set_bit(bits.pop(0), BoxOnWireBot(label, box_height, wire_label=qargs.pop(0),
+                                              conditional=conditional))
 
     def set_cl_multibox(self, creg, label, top_connect='┴'):
         """
@@ -946,14 +951,15 @@ def set_cl_multibox(self, creg, label, top_connect='┴'):
         clbit = [bit for bit in self.cregs if bit[0] == creg]
         self._set_multibox("cl", clbit, label, top_connect=top_connect)
 
-    def set_qu_multibox(self, bits, label):
+    def set_qu_multibox(self, bits, label, conditional=False):
         """
         Sets the multi qubit box.
         Args:
             bits (list[int]): A list of affected bits.
             label (string): The label for the multi qubit box.
+            conditional (bool): If the box has a conditional
         """
-        self._set_multibox("qu", bits, label)
+        self._set_multibox("qu", bits, label, conditional=conditional)
 
     def connect_with(self, wire_char):
         """


Test patch:
diff --git a/test/python/visualization/test_circuit_text_drawer.py b/test/python/visualization/test_circuit_text_drawer.py
--- a/test/python/visualization/test_circuit_text_drawer.py
+++ b/test/python/visualization/test_circuit_text_drawer.py
@@ -536,152 +536,6 @@ def test_text_no_barriers(self):
         circuit.h(qr2)
         self.assertEqual(str(_text_circuit_drawer(circuit, plotbarriers=False)), expected)
 
-    def test_text_conditional_1(self):
-        """ Conditional drawing with 1-bit-length regs."""
-        qasm_string = """
-        OPENQASM 2.0;
-        include "qelib1.inc";
-        qreg q[1];
-        creg c0[1];
-        creg c1[1];
-        if(c0==1) x q[0];
-        if(c1==1) x q[0];
-        """
-        expected = '\n'.join(["         ┌───┐  ┌───┐ ",
-                              "q_0: |0>─┤ X ├──┤ X ├─",
-                              "        ┌┴─┴─┴┐ └─┬─┘ ",
-                              "c0_0: 0 ╡ = 1 ╞═══╪═══",
-                              "        └─────┘┌──┴──┐",
-                              "c1_0: 0 ═══════╡ = 1 ╞",
-                              "               └─────┘"])
-
-        circuit = QuantumCircuit.from_qasm_str(qasm_string)
-        self.assertEqual(str(_text_circuit_drawer(circuit)), expected)
-
-    def test_text_conditional_2(self):
-        """ Conditional drawing with 2-bit-length regs."""
-        qasm_string = """
-        OPENQASM 2.0;
-        include "qelib1.inc";
-        qreg q[1];
-        creg c0[2];
-        creg c1[2];
-        if(c0==2) x q[0];
-        if(c1==2) x q[0];
-        """
-        expected = '\n'.join(["         ┌───┐  ┌───┐ ",
-                              "q_0: |0>─┤ X ├──┤ X ├─",
-                              "        ┌┴─┴─┴┐ └─┬─┘ ",
-                              "c0_0: 0 ╡     ╞═══╪═══",
-                              "        │ = 2 │   │   ",
-                              "c0_1: 0 ╡     ╞═══╪═══",
-                              "        └─────┘┌──┴──┐",
-                              "c1_0: 0 ═══════╡     ╞",
-                              "               │ = 2 │",
-                              "c1_1: 0 ═══════╡     ╞",
-                              "               └─────┘"])
-        circuit = QuantumCircuit.from_qasm_str(qasm_string)
-        self.assertEqual(str(_text_circuit_drawer(circuit)), expected)
-
-    def test_text_conditional_3(self):
-        """ Conditional drawing with 3-bit-length regs."""
-        qasm_string = """
-        OPENQASM 2.0;
-        include "qelib1.inc";
-        qreg q[1];
-        creg c0[3];
-        creg c1[3];
-        if(c0==3) x q[0];
-        if(c1==3) x q[0];
-        """
-        expected = '\n'.join(["         ┌───┐  ┌───┐ ",
-                              "q_0: |0>─┤ X ├──┤ X ├─",
-                              "        ┌┴─┴─┴┐ └─┬─┘ ",
-                              "c0_0: 0 ╡     ╞═══╪═══",
-                              "        │     │   │   ",
-                              "c0_1: 0 ╡ = 3 ╞═══╪═══",
-                              "        │     │   │   ",
-                              "c0_2: 0 ╡     ╞═══╪═══",
-                              "        └─────┘┌──┴──┐",
-                              "c1_0: 0 ═══════╡     ╞",
-                              "               │     │",
-                              "c1_1: 0 ═══════╡ = 3 ╞",
-                              "               │     │",
-                              "c1_2: 0 ═══════╡     ╞",
-                              "               └─────┘"])
-        circuit = QuantumCircuit.from_qasm_str(qasm_string)
-        self.assertEqual(str(_text_circuit_drawer(circuit)), expected)
-
-    def test_text_conditional_4(self):
-        """ Conditional drawing with 4-bit-length regs."""
-        qasm_string = """
-        OPENQASM 2.0;
-        include "qelib1.inc";
-        qreg q[1];
-        creg c0[4];
-        creg c1[4];
-        if(c0==4) x q[0];
-        if(c1==4) x q[0];
-        """
-        expected = '\n'.join(["         ┌───┐  ┌───┐ ",
-                              "q_0: |0>─┤ X ├──┤ X ├─",
-                              "        ┌┴─┴─┴┐ └─┬─┘ ",
-                              "c0_0: 0 ╡     ╞═══╪═══",
-                              "        │     │   │   ",
-                              "c0_1: 0 ╡     ╞═══╪═══",
-                              "        │ = 4 │   │   ",
-                              "c0_2: 0 ╡     ╞═══╪═══",
-                              "        │     │   │   ",
-                              "c0_3: 0 ╡     ╞═══╪═══",
-                              "        └─────┘┌──┴──┐",
-                              "c1_0: 0 ═══════╡     ╞",
-                              "               │     │",
-                              "c1_1: 0 ═══════╡     ╞",
-                              "               │ = 4 │",
-                              "c1_2: 0 ═══════╡     ╞",
-                              "               │     │",
-                              "c1_3: 0 ═══════╡     ╞",
-                              "               └─────┘"])
-        circuit = QuantumCircuit.from_qasm_str(qasm_string)
-        self.assertEqual(str(_text_circuit_drawer(circuit)), expected)
-
-    def test_text_conditional_5(self):
-        """ Conditional drawing with 5-bit-length regs."""
-        qasm_string = """
-        OPENQASM 2.0;
-        include "qelib1.inc";
-        qreg q[1];
-        creg c0[5];
-        creg c1[5];
-        if(c0==5) x q[0];
-        if(c1==5) x q[0];
-        """
-        expected = '\n'.join(["         ┌───┐  ┌───┐ ",
-                              "q_0: |0>─┤ X ├──┤ X ├─",
-                              "        ┌┴─┴─┴┐ └─┬─┘ ",
-                              "c0_0: 0 ╡     ╞═══╪═══",
-                              "        │     │   │   ",
-                              "c0_1: 0 ╡     ╞═══╪═══",
-                              "        │     │   │   ",
-                              "c0_2: 0 ╡ = 5 ╞═══╪═══",
-                              "        │     │   │   ",
-                              "c0_3: 0 ╡     ╞═══╪═══",
-                              "        │     │   │   ",
-                              "c0_4: 0 ╡     ╞═══╪═══",
-                              "        └─────┘┌──┴──┐",
-                              "c1_0: 0 ═══════╡     ╞",
-                              "               │     │",
-                              "c1_1: 0 ═══════╡     ╞",
-                              "               │     │",
-                              "c1_2: 0 ═══════╡ = 5 ╞",
-                              "               │     │",
-                              "c1_3: 0 ═══════╡     ╞",
-                              "               │     │",
-                              "c1_4: 0 ═══════╡     ╞",
-                              "               └─────┘"])
-        circuit = QuantumCircuit.from_qasm_str(qasm_string)
-        self.assertEqual(str(_text_circuit_drawer(circuit)), expected)
-
     def test_text_measure_html(self):
         """ The measure operator. HTML representation. """
         expected = '\n'.join(["<pre style=\"word-wrap: normal;"
@@ -1121,5 +975,402 @@ def test_text_justify_right(self):
                                                   vertically_compressed=False)), expected)
 
 
+class TestTextConditional(QiskitTestCase):
+    """Gates with conditionals"""
+
+    def test_text_conditional_1(self):
+        """ Conditional drawing with 1-bit-length regs."""
+        qasm_string = """
+        OPENQASM 2.0;
+        include "qelib1.inc";
+        qreg q[1];
+        creg c0[1];
+        creg c1[1];
+        if(c0==1) x q[0];
+        if(c1==1) x q[0];
+        """
+        expected = '\n'.join(["         ┌───┐  ┌───┐ ",
+                              "q_0: |0>─┤ X ├──┤ X ├─",
+                              "        ┌┴─┴─┴┐ └─┬─┘ ",
+                              "c0_0: 0 ╡ = 1 ╞═══╪═══",
+                              "        └─────┘┌──┴──┐",
+                              "c1_0: 0 ═══════╡ = 1 ╞",
+                              "               └─────┘"])
+
+        circuit = QuantumCircuit.from_qasm_str(qasm_string)
+        self.assertEqual(str(_text_circuit_drawer(circuit)), expected)
+
+    def test_text_conditional_2(self):
+        """ Conditional drawing with 2-bit-length regs."""
+        qasm_string = """
+        OPENQASM 2.0;
+        include "qelib1.inc";
+        qreg q[1];
+        creg c0[2];
+        creg c1[2];
+        if(c0==2) x q[0];
+        if(c1==2) x q[0];
+        """
+        expected = '\n'.join(["         ┌───┐  ┌───┐ ",
+                              "q_0: |0>─┤ X ├──┤ X ├─",
+                              "        ┌┴─┴─┴┐ └─┬─┘ ",
+                              "c0_0: 0 ╡     ╞═══╪═══",
+                              "        │ = 2 │   │   ",
+                              "c0_1: 0 ╡     ╞═══╪═══",
+                              "        └─────┘┌──┴──┐",
+                              "c1_0: 0 ═══════╡     ╞",
+                              "               │ = 2 │",
+                              "c1_1: 0 ═══════╡     ╞",
+                              "               └─────┘"])
+        circuit = QuantumCircuit.from_qasm_str(qasm_string)
+        self.assertEqual(str(_text_circuit_drawer(circuit)), expected)
+
+    def test_text_conditional_3(self):
+        """ Conditional drawing with 3-bit-length regs."""
+        qasm_string = """
+        OPENQASM 2.0;
+        include "qelib1.inc";
+        qreg q[1];
+        creg c0[3];
+        creg c1[3];
+        if(c0==3) x q[0];
+        if(c1==3) x q[0];
+        """
+        expected = '\n'.join(["         ┌───┐  ┌───┐ ",
+                              "q_0: |0>─┤ X ├──┤ X ├─",
+                              "        ┌┴─┴─┴┐ └─┬─┘ ",
+                              "c0_0: 0 ╡     ╞═══╪═══",
+                              "        │     │   │   ",
+                              "c0_1: 0 ╡ = 3 ╞═══╪═══",
+                              "        │     │   │   ",
+                              "c0_2: 0 ╡     ╞═══╪═══",
+                              "        └─────┘┌──┴──┐",
+                              "c1_0: 0 ═══════╡     ╞",
+                              "               │     │",
+                              "c1_1: 0 ═══════╡ = 3 ╞",
+                              "               │     │",
+                              "c1_2: 0 ═══════╡     ╞",
+                              "               └─────┘"])
+        circuit = QuantumCircuit.from_qasm_str(qasm_string)
+        self.assertEqual(str(_text_circuit_drawer(circuit)), expected)
+
+    def test_text_conditional_4(self):
+        """ Conditional drawing with 4-bit-length regs."""
+        qasm_string = """
+        OPENQASM 2.0;
+        include "qelib1.inc";
+        qreg q[1];
+        creg c0[4];
+        creg c1[4];
+        if(c0==4) x q[0];
+        if(c1==4) x q[0];
+        """
+        expected = '\n'.join(["         ┌───┐  ┌───┐ ",
+                              "q_0: |0>─┤ X ├──┤ X ├─",
+                              "        ┌┴─┴─┴┐ └─┬─┘ ",
+                              "c0_0: 0 ╡     ╞═══╪═══",
+                              "        │     │   │   ",
+                              "c0_1: 0 ╡     ╞═══╪═══",
+                              "        │ = 4 │   │   ",
+                              "c0_2: 0 ╡     ╞═══╪═══",
+                              "        │     │   │   ",
+                              "c0_3: 0 ╡     ╞═══╪═══",
+                              "        └─────┘┌──┴──┐",
+                              "c1_0: 0 ═══════╡     ╞",
+                              "               │     │",
+                              "c1_1: 0 ═══════╡     ╞",
+                              "               │ = 4 │",
+                              "c1_2: 0 ═══════╡     ╞",
+                              "               │     │",
+                              "c1_3: 0 ═══════╡     ╞",
+                              "               └─────┘"])
+        circuit = QuantumCircuit.from_qasm_str(qasm_string)
+        self.assertEqual(str(_text_circuit_drawer(circuit)), expected)
+
+    def test_text_conditional_5(self):
+        """ Conditional drawing with 5-bit-length regs."""
+        qasm_string = """
+        OPENQASM 2.0;
+        include "qelib1.inc";
+        qreg q[1];
+        creg c0[5];
+        creg c1[5];
+        if(c0==5) x q[0];
+        if(c1==5) x q[0];
+        """
+        expected = '\n'.join(["         ┌───┐  ┌───┐ ",
+                              "q_0: |0>─┤ X ├──┤ X ├─",
+                              "        ┌┴─┴─┴┐ └─┬─┘ ",
+                              "c0_0: 0 ╡     ╞═══╪═══",
+                              "        │     │   │   ",
+                              "c0_1: 0 ╡     ╞═══╪═══",
+                              "        │     │   │   ",
+                              "c0_2: 0 ╡ = 5 ╞═══╪═══",
+                              "        │     │   │   ",
+                              "c0_3: 0 ╡     ╞═══╪═══",
+                              "        │     │   │   ",
+                              "c0_4: 0 ╡     ╞═══╪═══",
+                              "        └─────┘┌──┴──┐",
+                              "c1_0: 0 ═══════╡     ╞",
+                              "               │     │",
+                              "c1_1: 0 ═══════╡     ╞",
+                              "               │     │",
+                              "c1_2: 0 ═══════╡ = 5 ╞",
+                              "               │     │",
+                              "c1_3: 0 ═══════╡     ╞",
+                              "               │     │",
+                              "c1_4: 0 ═══════╡     ╞",
+                              "               └─────┘"])
+        circuit = QuantumCircuit.from_qasm_str(qasm_string)
+        self.assertEqual(str(_text_circuit_drawer(circuit)), expected)
+
+    def test_text_conditional_cz_no_space(self):
+        """Conditional CZ without space"""
+        qr = QuantumRegister(2, 'qr')
+        cr = ClassicalRegister(1, 'cr')
+        circuit = QuantumCircuit(qr, cr)
+        circuit.cz(qr[0], qr[1]).c_if(cr, 1)
+
+        expected = '\n'.join(["                ",
+                              "qr_0: |0>───■───",
+                              "            │   ",
+                              "qr_1: |0>───■───",
+                              "         ┌──┴──┐",
+                              " cr_0: 0 ╡ = 1 ╞",
+                              "         └─────┘"])
+
+        self.assertEqual(str(_text_circuit_drawer(circuit)), expected)
+
+    def test_text_conditional_cz(self):
+        """Conditional CZ with a wire in the middle"""
+        qr = QuantumRegister(3, 'qr')
+        cr = ClassicalRegister(1, 'cr')
+        circuit = QuantumCircuit(qr, cr)
+        circuit.cz(qr[0], qr[1]).c_if(cr, 1)
+
+        expected = '\n'.join(["                ",
+                              "qr_0: |0>───■───",
+                              "            │   ",
+                              "qr_1: |0>───■───",
+                              "            │   ",
+                              "qr_2: |0>───┼───",
+                              "         ┌──┴──┐",
+                              " cr_0: 0 ╡ = 1 ╞",
+                              "         └─────┘"])
+
+        self.assertEqual(str(_text_circuit_drawer(circuit)), expected)
+
+    def test_text_conditional_cx_ct(self):
+        """Conditional CX (control-target) with a wire in the middle"""
+        qr = QuantumRegister(3, 'qr')
+        cr = ClassicalRegister(1, 'cr')
+        circuit = QuantumCircuit(qr, cr)
+        circuit.cx(qr[0], qr[1]).c_if(cr, 1)
+
+        expected = '\n'.join(["                ",
+                              "qr_0: |0>───■───",
+                              "          ┌─┴─┐ ",
+                              "qr_1: |0>─┤ X ├─",
+                              "          └─┬─┘ ",
+                              "qr_2: |0>───┼───",
+                              "         ┌──┴──┐",
+                              " cr_0: 0 ╡ = 1 ╞",
+                              "         └─────┘"])
+
+        self.assertEqual(str(_text_circuit_drawer(circuit)), expected)
+
+    def test_text_conditional_cx_tc(self):
+        """Conditional CX (target-control) with a wire in the middle"""
+        qr = QuantumRegister(3, 'qr')
+        cr = ClassicalRegister(1, 'cr')
+        circuit = QuantumCircuit(qr, cr)
+        circuit.cx(qr[1], qr[0]).c_if(cr, 1)
+
+        expected = '\n'.join(["          ┌───┐ ",
+                              "qr_0: |0>─┤ X ├─",
+                              "          └─┬─┘ ",
+                              "qr_1: |0>───■───",
+                              "            │   ",
+                              "qr_2: |0>───┼───",
+                              "         ┌──┴──┐",
+                              " cr_0: 0 ╡ = 1 ╞",
+                              "         └─────┘"])
+
+        self.assertEqual(str(_text_circuit_drawer(circuit)), expected)
+
+    def test_text_conditional_cu3_ct(self):
+        """Conditional Cu3 (control-target) with a wire in the middle"""
+        qr = QuantumRegister(3, 'qr')
+        cr = ClassicalRegister(1, 'cr')
+        circuit = QuantumCircuit(qr, cr)
+        circuit.cu3(pi / 2, pi / 2, pi / 2, qr[0], qr[1]).c_if(cr, 1)
+
+        expected = '\n'.join(["                                     ",
+                              "qr_0: |0>─────────────■──────────────",
+                              "         ┌────────────┴─────────────┐",
+                              "qr_1: |0>┤ U3(1.5708,1.5708,1.5708) ├",
+                              "         └────────────┬─────────────┘",
+                              "qr_2: |0>─────────────┼──────────────",
+                              "                   ┌──┴──┐           ",
+                              " cr_0: 0 ══════════╡ = 1 ╞═══════════",
+                              "                   └─────┘           "])
+
+        self.assertEqual(str(_text_circuit_drawer(circuit)), expected)
+
+    def test_text_conditional_cu3_tc(self):
+        """Conditional Cu3 (target-control) with a wire in the middle"""
+        qr = QuantumRegister(3, 'qr')
+        cr = ClassicalRegister(1, 'cr')
+        circuit = QuantumCircuit(qr, cr)
+        circuit.cu3(pi / 2, pi / 2, pi / 2, qr[1], qr[0]).c_if(cr, 1)
+
+        expected = '\n'.join(["         ┌──────────────────────────┐",
+                              "qr_0: |0>┤ U3(1.5708,1.5708,1.5708) ├",
+                              "         └────────────┬─────────────┘",
+                              "qr_1: |0>─────────────■──────────────",
+                              "                      │              ",
+                              "qr_2: |0>─────────────┼──────────────",
+                              "                   ┌──┴──┐           ",
+                              " cr_0: 0 ══════════╡ = 1 ╞═══════════",
+                              "                   └─────┘           "])
+
+        self.assertEqual(str(_text_circuit_drawer(circuit)), expected)
+
+    def test_text_conditional_ccx(self):
+        """Conditional CCX with a wire in the middle"""
+        qr = QuantumRegister(4, 'qr')
+        cr = ClassicalRegister(1, 'cr')
+        circuit = QuantumCircuit(qr, cr)
+        circuit.ccx(qr[0], qr[1], qr[2]).c_if(cr, 1)
+
+        expected = '\n'.join(["                ",
+                              "qr_0: |0>───■───",
+                              "            │   ",
+                              "qr_1: |0>───■───",
+                              "          ┌─┴─┐ ",
+                              "qr_2: |0>─┤ X ├─",
+                              "          └─┬─┘ ",
+                              "qr_3: |0>───┼───",
+                              "         ┌──┴──┐",
+                              " cr_0: 0 ╡ = 1 ╞",
+                              "         └─────┘"])
+
+        self.assertEqual(str(_text_circuit_drawer(circuit)), expected)
+
+    def test_text_conditional_ccx_no_space(self):
+        """Conditional CCX without space"""
+        qr = QuantumRegister(3, 'qr')
+        cr = ClassicalRegister(1, 'cr')
+        circuit = QuantumCircuit(qr, cr)
+        circuit.ccx(qr[0], qr[1], qr[2]).c_if(cr, 1)
+
+        expected = '\n'.join(["                ",
+                              "qr_0: |0>───■───",
+                              "            │   ",
+                              "qr_1: |0>───■───",
+                              "          ┌─┴─┐ ",
+                              "qr_2: |0>─┤ X ├─",
+                              "         ┌┴─┴─┴┐",
+                              " cr_0: 0 ╡ = 1 ╞",
+                              "         └─────┘"])
+
+        self.assertEqual(str(_text_circuit_drawer(circuit)), expected)
+
+    def test_text_conditional_h(self):
+        """Conditional H with a wire in the middle"""
+        qr = QuantumRegister(2, 'qr')
+        cr = ClassicalRegister(1, 'cr')
+        circuit = QuantumCircuit(qr, cr)
+        circuit.h(qr[0]).c_if(cr, 1)
+
+        expected = '\n'.join(["          ┌───┐ ",
+                              "qr_0: |0>─┤ H ├─",
+                              "          └─┬─┘ ",
+                              "qr_1: |0>───┼───",
+                              "         ┌──┴──┐",
+                              " cr_0: 0 ╡ = 1 ╞",
+                              "         └─────┘"])
+
+        self.assertEqual(str(_text_circuit_drawer(circuit)), expected)
+
+    def test_text_conditional_swap(self):
+        """Conditional SWAP"""
+        qr = QuantumRegister(3, 'qr')
+        cr = ClassicalRegister(1, 'cr')
+        circuit = QuantumCircuit(qr, cr)
+        circuit.swap(qr[0], qr[1]).c_if(cr, 1)
+
+        expected = '\n'.join(["                ",
+                              "qr_0: |0>───X───",
+                              "            │   ",
+                              "qr_1: |0>───X───",
+                              "            │   ",
+                              "qr_2: |0>───┼───",
+                              "         ┌──┴──┐",
+                              " cr_0: 0 ╡ = 1 ╞",
+                              "         └─────┘"])
+
+        self.assertEqual(str(_text_circuit_drawer(circuit)), expected)
+
+    def test_text_conditional_cswap(self):
+        """Conditional CSwap """
+        qr = QuantumRegister(4, 'qr')
+        cr = ClassicalRegister(1, 'cr')
+        circuit = QuantumCircuit(qr, cr)
+        circuit.cswap(qr[0], qr[1], qr[2]).c_if(cr, 1)
+
+        expected = '\n'.join(["                ",
+                              "qr_0: |0>───■───",
+                              "            │   ",
+                              "qr_1: |0>───X───",
+                              "            │   ",
+                              "qr_2: |0>───X───",
+                              "            │   ",
+                              "qr_3: |0>───┼───",
+                              "         ┌──┴──┐",
+                              " cr_0: 0 ╡ = 1 ╞",
+                              "         └─────┘"])
+
+        self.assertEqual(str(_text_circuit_drawer(circuit)), expected)
+
+    def test_conditional_reset(self):
+        """ Reset drawing. """
+        qr = QuantumRegister(2, 'qr')
+        cr = ClassicalRegister(1, 'cr')
+
+        circuit = QuantumCircuit(qr, cr)
+        circuit.reset(qr[0]).c_if(cr, 1)
+
+        expected = '\n'.join(["                ",
+                              "qr_0: |0>──|0>──",
+                              "            │   ",
+                              "qr_1: |0>───┼───",
+                              "         ┌──┴──┐",
+                              " cr_0: 0 ╡ = 1 ╞",
+                              "         └─────┘"])
+
+        self.assertEqual(str(_text_circuit_drawer(circuit)), expected)
+
+    def test_conditional_multiplexer(self):
+        """ Test Multiplexer."""
+        cx_multiplexer = Gate('multiplexer', 2, [numpy.eye(2), numpy.array([[0, 1], [1, 0]])])
+        qr = QuantumRegister(3, name='qr')
+        cr = ClassicalRegister(1, 'cr')
+        qc = QuantumCircuit(qr, cr)
+        qc.append(cx_multiplexer.c_if(cr, 1), [qr[0], qr[1]])
+
+        expected = '\n'.join(["         ┌──────────────┐",
+                              "qr_0: |0>┤0             ├",
+                              "         │  multiplexer │",
+                              "qr_1: |0>┤1             ├",
+                              "         └──────┬───────┘",
+                              "qr_2: |0>───────┼────────",
+                              "             ┌──┴──┐     ",
+                              " cr_0: 0 ════╡ = 1 ╞═════",
+                              "             └─────┘     "])
+
+        self.assertEqual(str(_text_circuit_drawer(qc)), expected)
+
+
 if __name__ == '__main__':
     unittest.main()