diff --git a/copyAsMarkdown.spBundle/command.plist b/copyAsMarkdown.spBundle/command.plist index 4f7d178..d426cb5 100644 --- a/copyAsMarkdown.spBundle/command.plist +++ b/copyAsMarkdown.spBundle/command.plist @@ -48,19 +48,13 @@ class CopyAsMarkdown $result = []; $str = ''; foreach ($columns as $column) { - if (!empty($str)) { - $str .= "|"; - } - $str .= $column; + $str .= "|" . $column; } $result[] = $str; $str = ''; for($i=0; $i<count($columns); $i++) { - if (!empty($str)) { - $str .= "|"; - } - $str .= "---"; + $str .= "|---"; } $result[] = $str; @@ -85,10 +79,7 @@ class CopyAsMarkdown foreach ($rows as $row) { $str = ''; foreach ($row as $val) { - if (!empty($str)) { - $str .= "|"; - } - $str .= str_replace(array("\n", "\r"), '', nl2br($val)); + $str .= "|" . str_replace(array("\n", "\r"), '', nl2br($val)); } $result[] = $str; } diff --git a/lib/CopyAsMarkdown/CopyAsMarkdown.php b/lib/CopyAsMarkdown/CopyAsMarkdown.php index 623f819..e400b50 100644 --- a/lib/CopyAsMarkdown/CopyAsMarkdown.php +++ b/lib/CopyAsMarkdown/CopyAsMarkdown.php @@ -41,19 +41,13 @@ protected function _createHeaderRows(array $columns) $result = []; $str = ''; foreach ($columns as $column) { - if (!empty($str)) { - $str .= "|"; - } - $str .= $column; + $str .= "|" . $column; } $result[] = $str; $str = ''; for($i=0; $iassertEquals($expected, $this->copyAsMarkdown->createHeaderRows(array('hoge', 'fuga'))); } + public function testCreateHeaderRows_WhenHasOneColumn() + { + $expected = '|hoge +|---'; + $this->assertEquals($expected, $this->copyAsMarkdown->createHeaderRows(array('hoge'))); + } public function testCalculateColumnCount() { @@ -26,17 +32,25 @@ public function testCalculateColumnCount() public function testCreateDataRows() { - $expected = 'a|b|c -d|e|f'; + $expected = '|a|b|c +|d|e|f'; $this->assertEquals($expected, $this->copyAsMarkdown->createDataRows(array( array('a', 'b', 'c'), array('d', 'e', 'f'), ))); } + public function testCreateDataRows_WhenHasOneColumn() + { + $expected = '|a'; + $this->assertEquals($expected, $this->copyAsMarkdown->createDataRows(array( + array('a'), + ))); + } + public function testCreateDataRows_ReturnLineFeedRemovedData_WhenHasLineFeedInData() { - $expected = 'a|b1
b2
b3|c'; + $expected = '|a|b1
b2
b3|c'; $this->assertEquals($expected, $this->copyAsMarkdown->createDataRows(array( array('a', 'b1 b2