Comments (3)
Thanks for putting some thought into this.
To reduce the repetition of the same boilerplate code in every test, we could define some helper functions. For example, we could have a trio of functions test_parse_expression_tidyverse()
, test_parse_expression_base()
, and test_parse_expression_generic()
. The generic
one would simply call both of the other two.
from queryparser.
Regarding whether to (1) test the translation or (2) test the outcome:
I think (1) is safer and more general. It eliminates the possibility that the particular input values used in the test coincidentally worked but will not work in general.
from queryparser.
I'm thinking there are two options for "indirect" translations:
- Test the translation
test_that("ifnull() function translates correctly", {
SQL <- "ifnull(a, b)"
R <- "ifelse(is.na(a), b, a)"
expect_equal(parse_expression(SQL, tidy = FALSE), str2lang(R))
expect_equal(parse_expression(SQL, tidy = TRUE), str2lang(R))
})
- Test the outcome
test_that("ifnull() function translates correctly", {
a <- c(1, 2, NA)
b <- c(7, 8, 9)
SQL <- "ifnull(a, b)"
answer <- c(1, 2, 9)
untidy <- eval(parse_expression(SQL, tidy = FALSE))
tidy <- eval(parse_expression(SQL, tidy = TRUE))
expect_equal(untidy, answer)
expect_equal(tidy, answer)
})
I think I prefer the 2nd option, though it is more involved. Thoughts?
from queryparser.
Related Issues (20)
- Translation of multiple CAST and BETWEEN in one expression fails HOT 1
- Set an attribute indicating whether each expression in the ORDER BY list aggregates HOT 1
- Translate NULLS FIRST and NULLS LAST in ORDER BY clause
- Errors in translation of BETWEEN expressions with quoted operands when tidyverse = FALSE
- Remove line comments and block comments from query
- Translation of coalesce() fails when tidyverse = FALSE and arguments are expressions
- Add support for CASE expressions when tidyverse = TRUE HOT 1
- Translate coalesce() to a vectorized expression when tidyverse = FALSE
- Add support for CASE expressions when tidyverse = FALSE
- Add support for table aliases HOT 1
- Add support for SQL-92-style join queries
- Fix problems with non-ASCII characters in queries HOT 1
- Allow parentheses enclosing table names and joins in FROM clause HOT 1
- Add support for UNION HOT 3
- Parse queries with no whitespace characters separating keywords
- Add translation for substring_index() HOT 6
- Silence "truncating string with embedded nuls" warnings
- Allow syntactically invalid column names in backticks HOT 2
- Throw error if called from an incompatible version of tidyquery HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from queryparser.