universal-ctags / citre

A superior code reading & auto-completion tool with pluggable backends.
GNU General Public License v3.0
326 stars 26 forks source link

Add test case for testing citre-lang-c-definition-sorter #53

Closed masatake closed 3 years ago

masatake commented 3 years ago

This change is for testing the code newly added in #52.

AmaiKinono commented 3 years ago

Thanks for the patch!

I don't quite like the idea of making use of xref (the marker and extra-move things is really, really smart, though). What do you think of this way:

  1. We use citre-get-definitions to get a list of tags.
  2. We compare this list with a serialized list in a file.

The (de)serialization can be done with:

(defun citre--print-value-to-file (filename value)
  "Print VALUE to file FILENAME."
  (with-temp-file filename
    (prin1 value (current-buffer))))

(defun citre--read-value-from-file (filename)
  "Read value from file FILENAME."
  (with-temp-buffer
    (insert-file-contents filename)
    (goto-char (point-min))
    (read (current-buffer))))

I don't have experience of comparing hash tables, though. I think what we can do is:

  1. We write fields we care about to the serialized hash tables. For this test case, we only need to write the input field in the tags.
  2. For each hash table in the list, we iterate over the keys in the serialized one, and only compare their values.
masatake commented 3 years ago

I will rework this item.

masatake commented 3 years ago

Updated. I used citre-get-definitions as you wrote. I agree that using citre-get-definitions is much better than extracting the contents of xref buffer.

However, I think using the contents of xref buffer as expected output is very intuitive for developers of test cases. So I defined defs-to-xref in test.el and use it.

AmaiKinono commented 3 years ago

Thanks for your beautiful work ;)