In my last post about unit testing I wrote about the fact that that unit testing will shine a light on what you don’t understand about your code or logic. This post will be a short continuation of that post showing how my attempt to understand how RapidYAML parses YAML and the experimentation that I had to go through to get to that test. Experimentation is the process of coming up with a question to answer and seeking the answer to the question.
In this post I’ll be looking at the tests for the parser in the EveSDEImporter project as it exists in this revision.
The Question: How Do I Access Data Elements From The Parsed YAML?
The goal of the EveSDEImporter project is to pull the data out of the YAML files provided as part of the Eve data, create database tables in an RDBMS, and insert the data. This means that I’m going to have to understand how to access the map data (key/value) data in the sequences. I’ll have to grab the keys to create a table then grab the values in each sequence to be able to insert them as records. The gap in my understanding was: Which elements in the tree correspond to the sequences and which correspond to the maps which I can pull the keys and values from?
The Experiments: Using Assertions To Ask Questions About The Data
Some of my confusion about how the data is parsed is how questions will be answered when you’re looking at a Tree versus a Node. As you can see in this revision I thought that the tree object would be a sequence that, underneath, held mappings. It wasn’t until I used an assertion that failed that I found out that tree was considered a map. While this stumped me for a bit I realized that I should have been using nodes to find the actual data that I was interested in.
What the revision doesn’t show you, however, is that it took writing and re-writing the assertions until they passed for me to understand how the data really works. This process of learning is not only beneficial to the author’s understanding of how the code should work. It acts as a guide to developers new to the code for how it is intended to work.
Next Steps: Figure Out How To Iterate Over The Sequences
The next steps for me in this project is to understand how to use the tree object to appropriately iterate over the nodes containing data such that I can use them to achieve the goal of the program. My approach to accomplishing this will be to write a test where I attempt to do just this. The process of writing the assertions will help me learn how the Rapidyaml code works. In addition it will guide how I write further parts of my own code. I am looking forward to sharing my future discoveries with you!