# Path: publications/templatetags/publication_extras.py
# def tex_parse(string):
# 	"""
# 	Renders some basic TeX math to HTML.
# 	"""
# 
# 	string = string.replace('{', '').replace('}', '')
# 	def tex_replace(match):
# 		return \
# 			sub(r'\^(\w)', r'<sup>\1</sup>',
# 			sub(r'\^\{(.*?)\}', r'<sup>\1</sup>',
# 			sub(r'\_(\w)', r'<sub>\1</sub>',
# 			sub(r'\_\{(.*?)\}', r'<sub>\1</sub>',
# 			sub(r'\\(' + GREEK_LETTERS + ')', r'&\1;', match.group(1))))))
# 	return mark_safe(sub(r'\$([^\$]*)\$', tex_replace, escape(string)))


from django.test import TestCase
from django.contrib.auth.models import User
from django.urls import reverse
from django.db import transaction
from django.template import Template, RequestContext
from django.http import HttpRequest
from publications.models import Publication, Type, CustomLink, List
from publications.templatetags.publication_extras import tex_parse
		self.assertEqual(self.client.get('/publications/').status_code, 200)
		self.assertEqual(self.client.get('/admin/publications/type/6/move-up/', follow=True).status_code, 200)
		self.assertEqual(self.client.get('/admin/publications/type/6/move-down/', follow=True).status_code, 200)


	def test_extras(self):
		link = CustomLink.objects.create(publication_id=1, description='Test', url='http://test.com')
		link.save()

		publication = Publication.objects.get(pk=1)
		lists = List.objects.filter(list__iexact='highlights')

		self.assertEqual(len(lists), 1)

		# add publication to list
		publication.lists.add(lists[0])

		# render list
		tpl = Template("""
			{% load publication_extras %}
			{% get_publication 1 %}
			{% get_publication_list 'highlights' 'publications/publications_with_thumbnails.html' %}
			{% get_publication 10 %}
			{% get_publications %}
			""")

		self.assertGreater(len(tpl.render(RequestContext(HttpRequest())).strip()), 0)

		# tex_parse is used to replace simple LaTeX code in publication titles
		self.assertEqual(tex_parse(u'$L_p$-spherical'), u'L<sub>p</sub>-spherical')

# Path: publications/templatetags/publication_extras.py
# def tex_parse(string):
# 	"""
# 	Renders some basic TeX math to HTML.
# 	"""
# 
# 	string = string.replace('{', '').replace('}', '')
# 	def tex_replace(match):
# 		return \
# 			sub(r'\^(\w)', r'<sup>\1</sup>',
# 			sub(r'\^\{(.*?)\}', r'<sup>\1</sup>',
# 			sub(r'\_(\w)', r'<sub>\1</sub>',
# 			sub(r'\_\{(.*?)\}', r'<sub>\1</sub>',
# 			sub(r'\\(' + GREEK_LETTERS + ')', r'&\1;', match.group(1))))))
# 	return mark_safe(sub(r'\$([^\$]*)\$', tex_replace, escape(string)))


# Path: publications/tests/tests.py
from django.test import TestCase
from django.contrib.auth.models import User
from django.urls import reverse
from django.db import transaction
from django.template import Template, RequestContext
from django.http import HttpRequest
from publications.models import Publication, Type, CustomLink, List
from publications.templatetags.publication_extras import tex_parse

		self.assertEqual(self.client.get('/publications/').status_code, 200)
		self.assertEqual(self.client.get('/admin/publications/type/6/move-up/', follow=True).status_code, 200)
		self.assertEqual(self.client.get('/admin/publications/type/6/move-down/', follow=True).status_code, 200)


	def test_extras(self):
		link = CustomLink.objects.create(publication_id=1, description='Test', url='http://test.com')
		link.save()

		publication = Publication.objects.get(pk=1)
		lists = List.objects.filter(list__iexact='highlights')

		self.assertEqual(len(lists), 1)

		# add publication to list
		publication.lists.add(lists[0])

		# render list
		tpl = Template("""
			{% load publication_extras %}
			{% get_publication 1 %}
			{% get_publication_list 'highlights' 'publications/publications_with_thumbnails.html' %}
			{% get_publication 10 %}
			{% get_publications %}
			""")

		self.assertGreater(len(tpl.render(RequestContext(HttpRequest())).strip()), 0)

		# tex_parse is used to replace simple LaTeX code in publication titles
		self.assertEqual(tex_parse(u'$L_p$-spherical'), u'L<sub>p</sub>-spherical')

		self.assertEqual(tex_parse(u'$L^2$-spherical'), u'L<sup>2</sup>-spherical')