File indexing completed on 2024-05-12 05:53:55
0001 /* 0002 * Copyright (c) 2018 Sune Vuorela <sune@vuorela.dk> 0003 * 0004 * Permission is hereby granted, free of charge, to any person 0005 * obtaining a copy of this software and associated documentation 0006 * files (the "Software"), to deal in the Software without 0007 * restriction, including without limitation the rights to use, 0008 * copy, modify, merge, publish, distribute, sublicense, and/or sell 0009 * copies of the Software, and to permit persons to whom the 0010 * Software is furnished to do so, subject to the following 0011 * conditions: 0012 * 0013 * The above copyright notice and this permission notice shall be 0014 * included in all copies or substantial portions of the Software. 0015 * 0016 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 0017 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 0018 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 0019 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 0020 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 0021 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 0022 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 0023 * OTHER DEALINGS IN THE SOFTWARE. 0024 */ 0025 0026 #include "ingredientsextractor.h" 0027 #include <QTest> 0028 0029 class IngredientsExtractorTest : public QObject 0030 { 0031 Q_OBJECT 0032 private Q_SLOTS: 0033 void testThings(); 0034 void testThings_data(); 0035 }; 0036 0037 Q_DECLARE_METATYPE(IngredientsExtractor::Ingredient); 0038 0039 0040 void IngredientsExtractorTest::testThings() 0041 { 0042 QFETCH(QString, input); 0043 QFETCH(IngredientsExtractor::Ingredient, result); 0044 0045 auto parsedResult = IngredientsExtractor::parseLine(input); 0046 QCOMPARE(parsedResult.amount,result.amount); 0047 QCOMPARE(parsedResult.unit,result.unit); 0048 QCOMPARE(parsedResult.ingredient,result.ingredient); 0049 0050 } 0051 0052 0053 void IngredientsExtractorTest::testThings_data() 0054 { 0055 QTest::addColumn<QString>("input"); 0056 QTest::addColumn<IngredientsExtractor::Ingredient>("result"); 0057 0058 QTest::newRow("simple") << " * 1.5 kg mel" << IngredientsExtractor::Ingredient{"1.5","kg","mel"}; 0059 QTest::newRow("simple almost") << "* 1.5 kg mel" << IngredientsExtractor::Ingredient{"1.5","kg","mel"}; 0060 QTest::newRow("simple extra spaces") << "* 1.5 kg mel" << IngredientsExtractor::Ingredient{"1.5","kg","mel"}; 0061 QTest::newRow("half baked") << "* 1.5 kg " << IngredientsExtractor::Ingredient{}; 0062 QTest::newRow("with comment") << " * 1.5 kg mel, alternativt grahamsmel" << IngredientsExtractor::Ingredient{"1.5","kg","mel"}; 0063 QTest::newRow("with comment, no parsable ingredient") << " * mel, alternativt grahamsmel" << IngredientsExtractor::Ingredient{}; 0064 QTest::newRow("just comment") << " , foo" << IngredientsExtractor::Ingredient{}; 0065 QTest::newRow("empty") << QString() << IngredientsExtractor::Ingredient{}; 0066 QTest::newRow("almost empty") << " * " << IngredientsExtractor::Ingredient{}; 0067 QTest::newRow("simple dash") << " - 1.5 kg mel" << IngredientsExtractor::Ingredient{"1.5","kg","mel"}; 0068 QTest::newRow("simple almost dash") << "- 1.5 kg mel" << IngredientsExtractor::Ingredient{"1.5","kg","mel"}; 0069 QTest::newRow("simple extra spaces dash") << "- 1.5 kg mel" << IngredientsExtractor::Ingredient{"1.5","kg","mel"}; 0070 QTest::newRow("half baked dash") << "- 1.5 kg " << IngredientsExtractor::Ingredient{}; 0071 QTest::newRow("with comment dash") << " - 1.5 kg mel, alternativt grahamsmel" << IngredientsExtractor::Ingredient{"1.5","kg","mel"}; 0072 QTest::newRow("with comment, no parsable ingredient dash") << " - mel, alternativt grahamsmel" << IngredientsExtractor::Ingredient{}; 0073 QTest::newRow("almost empty dash") << " - " << IngredientsExtractor::Ingredient{}; 0074 } 0075 0076 0077 0078 QTEST_APPLESS_MAIN(IngredientsExtractorTest) 0079 0080 #include "ingredientsextractortest.moc"