We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent be4f208 commit 73f4954Copy full SHA for 73f4954
115/indents.py
@@ -0,0 +1,12 @@
1
+def count_indents(text):
2
+ """Takes a string and counts leading white spaces, return int count"""
3
+ counts = 0
4
+ for char in text:
5
+ if char.isspace() and char != "\t" and char !="\n":
6
+ counts += 1
7
+ elif char.isalpha():
8
+ break
9
+ return counts
10
+
11
+# print(count_indents("\t\toxzcxc"))
12
+# "ddd dd dd".
115/test_indents.py
@@ -0,0 +1,16 @@
+import pytest
+from indents import count_indents
+@pytest.mark.parametrize("input_string, count", [
+ ('string ', 0),
+ (' string', 2),
+ (' string', 4),
+ (' string', 12),
+ ('\t\tstring', 0),
+ (' str ing', 2),
13
+ (' str ', 2),
14
+])
15
+def test_count_indents(input_string, count):
16
+ assert count_indents(input_string) == count
0 commit comments