spec/flydata/command/sync_spec.rb in flydata-0.1.4 vs spec/flydata/command/sync_spec.rb in flydata-0.1.5
- old
+ new
@@ -1160,9 +1160,58 @@
let(:target_line) { "INSERT INTO `test_table` VALUES (1,'D:\\\\download\\\\','2014-04-15 13:49:14');" }
it 'should escape back slash' do
expect(subject).to eq([['1',"D:\\download\\",'2014-04-15 13:49:14']])
end
end
+
+ context 'when comma is the first character of a string' do
+ let(:target_line) { "INSERT INTO `test_table` VALUES (1,',9','2014-04-15 13:49:14');" }
+ it 'should parse the string correctly' do
+ expect(subject).to eq([['1',',9','2014-04-15 13:49:14']])
+ end
+ end
+
+ context 'when comma is the last character of a string' do
+ let(:target_line) { "INSERT INTO `test_table` VALUES (1,'9,','2014-04-15 13:49:14');" }
+ it 'should parse the string correctly' do
+ expect(subject).to eq([['1','9,','2014-04-15 13:49:14']])
+ end
+ end
+
+ context 'when a string consists of a comma' do
+ let(:target_line) { "INSERT INTO `test_table` VALUES (1,',','2014-04-15 13:49:14');" }
+ it 'should parse the string correctly' do
+ expect(subject).to eq([['1',',','2014-04-15 13:49:14']])
+ end
+ end
+
+ context 'when two commas are given as a string' do
+ let(:target_line) { "INSERT INTO `test_table` VALUES (1,',,','2014-04-15 13:49:14');" }
+ it 'should parse the string correctly' do
+ expect(subject).to eq([['1',',,','2014-04-15 13:49:14']])
+ end
+ end
+
+ context 'when an empty string value is given' do
+ let(:target_line) { "INSERT INTO `test_table` VALUES (1,'','2014-04-15 13:49:14');" }
+ it 'should parse the string correctly' do
+ expect(subject).to eq([['1','','2014-04-15 13:49:14']])
+ end
+ end
+
+ context 'when a value consists of a comma followed by closing bracket' do
+ let(:target_line) { "INSERT INTO `test_table` VALUES (1,'),ksd','2014-04-15 13:49:14');" }
+ it 'should parse the string correctly' do
+ expect(subject).to eq([['1','),ksd','2014-04-15 13:49:14']])
+ end
+ end
+
+ context 'when there is a white space before the closing bracket' do
+ let(:target_line) { "INSERT INTO `test_table` VALUES (1,'aa','2014-04-15 13:49:14' );" }
+ it 'should fail to parse. This is intentional for performance reason' do
+ expect{subject}.to raise_error
+ end
+ end
end
end
end
end